SPIRV-Tools/source
Jaebaek Seo c2b2b57885
Add DebugValue for invisible store in single_store_elim (#4002)
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: df4198e50e.
2020-11-04 13:43:59 -05:00
..
fuzz spirv-fuzz: Fixes to pass management (#4011) 2020-11-04 10:45:53 +00:00
link CMake: Add SPIRV_TOOLS_BUILD_STATIC flag (#3910) 2020-10-29 09:25:26 -04:00
opt Add DebugValue for invisible store in single_store_elim (#4002) 2020-11-04 13:43:59 -05:00
reduce CMake: Add SPIRV_TOOLS_BUILD_STATIC flag (#3910) 2020-10-29 09:25:26 -04:00
util Support constant-folding UConvert and SConvert (#2960) 2019-10-16 16:29:55 -04:00
val spirv-val: Allow the ViewportIndex and Layer built-ins on SPIR-V 1.5 (#3986) 2020-10-28 14:05:06 -04:00
assembly_grammar.cpp Add validation for SPV_NV_cooperative_matrix (#2404) 2019-02-25 17:43:11 -05:00
assembly_grammar.h Cleanup includes. (#1795) 2018-08-03 15:06:09 -04:00
binary.cpp Validate SPIRV Version number when parsing binary header (#3834) 2020-09-23 11:59:41 -04:00
binary.h Cleanup includes. (#1795) 2018-08-03 15:06:09 -04:00
cfa.h Avoid copying a ref in a loop (#4000) 2020-10-29 09:20:45 -04:00
CMakeLists.txt CMake: Add SPIRV_TOOLS_BUILD_STATIC flag (#3910) 2020-10-29 09:25:26 -04:00
diagnostic.cpp Remove source/message.h (#1838) 2018-08-14 15:41:21 -04:00
diagnostic.h Rewrite include guards (#1793) 2018-08-03 08:05:33 -04:00
disassemble.cpp [spirv-dis] Add some context comments to disassembly. (#3847) 2020-09-28 10:59:50 -04:00
disassemble.h Rewrite include guards (#1793) 2018-08-03 08:05:33 -04:00
enum_set.h Instrument: Debug Printf support (#3215) 2020-03-12 09:19:52 -04:00
enum_string_mapping.cpp Cleanup includes. (#1795) 2018-08-03 15:06:09 -04:00
enum_string_mapping.h Cleanup includes. (#1795) 2018-08-03 15:06:09 -04:00
ext_inst.cpp Validator support for non-semantic clspv reflection (#3618) 2020-07-30 12:08:53 -04:00
ext_inst.h Handle conflict between debug info and existing validation rule (#3104) 2020-01-23 17:04:30 -05:00
extensions.cpp Cleanup includes. (#1795) 2018-08-03 15:06:09 -04:00
extensions.h Cleanup includes. (#1795) 2018-08-03 15:06:09 -04:00
instruction.h Cleanup includes. (#1795) 2018-08-03 15:06:09 -04:00
latest_version_glsl_std_450_header.h Rewrite include guards (#1793) 2018-08-03 08:05:33 -04:00
latest_version_opencl_std_header.h Rewrite include guards (#1793) 2018-08-03 08:05:33 -04:00
latest_version_spirv_header.h Rewrite include guards (#1793) 2018-08-03 08:05:33 -04:00
libspirv.cpp Add SpirvTools::IsValid(). (#2326) 2019-01-24 09:45:09 -05:00
macro.h Rewrite include guards (#1793) 2018-08-03 08:05:33 -04:00
name_mapper.cpp Update some language usage. (#3611) 2020-07-29 13:50:58 -04:00
name_mapper.h Cleanup includes. (#1795) 2018-08-03 15:06:09 -04:00
opcode.cpp spirv-fuzz: Add bit instruction synonym transformation (#3775) 2020-09-15 23:36:23 +01:00
opcode.h spirv-fuzz: Add bit instruction synonym transformation (#3775) 2020-09-15 23:36:23 +01:00
operand.cpp Support SPV_KHR_fragment_shading_rate (#3943) 2020-10-20 08:00:13 -04:00
operand.h Handle conflict between debug info and existing validation rule (#3104) 2020-01-23 17:04:30 -05:00
parsed_operand.cpp Replace asserts with returns 2018-08-08 15:13:04 -04:00
parsed_operand.h Cleanup includes. (#1795) 2018-08-03 15:06:09 -04:00
pch_source.cpp Enable precompiled headers for spirv-tools(-shared) and some unit tests (#2026) 2018-11-06 09:26:23 -05:00
pch_source.h Enable precompiled headers for spirv-tools(-shared) and some unit tests (#2026) 2018-11-06 09:26:23 -05:00
print.cpp build: cmake: Add support for Fuchsia. (#3062) 2019-11-26 16:22:59 -05:00
print.h Rewrite include guards (#1793) 2018-08-03 08:05:33 -04:00
software_version.cpp Add missing function parameters in libspirv.h 2018-04-03 10:10:43 -04:00
spirv_constant.h Cleanup includes. (#1795) 2018-08-03 15:06:09 -04:00
spirv_definition.h Cleanup includes. (#1795) 2018-08-03 15:06:09 -04:00
spirv_endian.cpp Cleanup includes. (#1795) 2018-08-03 15:06:09 -04:00
spirv_endian.h Rewrite include guards (#1793) 2018-08-03 08:05:33 -04:00
spirv_fuzzer_options.cpp spirv-fuzz: Add pass recommendations (#3757) 2020-09-18 15:51:35 +01:00
spirv_fuzzer_options.h spirv-fuzz: Add pass recommendations (#3757) 2020-09-18 15:51:35 +01:00
spirv_optimizer_options.cpp Add —preserve-bindings and —preserve-spec-constants (#2693) 2019-07-10 14:12:19 -04:00
spirv_optimizer_options.h Add —preserve-bindings and —preserve-spec-constants (#2693) 2019-07-10 14:12:19 -04:00
spirv_reducer_options.cpp spirv-reduce: Support reducing a specific function (#3774) 2020-09-11 06:29:43 +01:00
spirv_reducer_options.h spirv-reduce: Support reducing a specific function (#3774) 2020-09-11 06:29:43 +01:00
spirv_target_env.cpp Add spvParseVulkanEnv (#3142) 2020-01-23 17:20:32 -05:00
spirv_target_env.h Validate that in OpenGL env block variables have Binding (#2685) 2019-07-02 08:11:20 -04:00
spirv_validator_options.cpp Make pointers to isomorphic type interchangeable with option. (#2570) 2019-05-13 13:48:17 -04:00
spirv_validator_options.h Make pointers to isomorphic type interchangeable with option. (#2570) 2019-05-13 13:48:17 -04:00
table.cpp Add basic support for Vulkan 1.2: SPV_ENV_VULKAN_1_2 2020-01-14 20:06:19 -05:00
table.h Use last version (#2578) 2019-05-10 11:02:01 -04:00
text_handler.cpp Avoid GCC8 warning in text_handler.cpp. (#2197) 2018-12-13 15:03:28 -05:00
text_handler.h Remove source/message.h (#1838) 2018-08-14 15:41:21 -04:00
text.cpp Support OpenCL.DebugInfo.100 extended instruction set (#3080) 2019-12-19 17:16:26 -05:00
text.h Cleanup includes. (#1795) 2018-08-03 15:06:09 -04:00