Commit Graph

987 Commits

Author SHA1 Message Date
Steven Perron
1082de6bb3
Handle overflowing id in merge return (#4606)
If the ids overflow when creating an integer constant in the ir_builder, there will be a nullptr dereference.  This is happening from inside merge return.

We need to propagate the error up, and make sure it is handled appropriately.
2021-11-01 08:45:32 -04:00
Steven Perron
6c7885dbde
Change branch handling in ADCE to fix errors (#4596)
Consider the new test case.  The conditional branch in the continue
block is never marked as live.  However, `IsDead` will say it is not
dead, so it does not get deleted.  Because it was never marked as live,
`%false` was not mark as live either, but it gets deleted.  This results
in invalid code.

To fix this properly, we had to reconsider how branches are handle.  We
make the following changes:

1) Terminator instructions that are not branch or OpUnreachable must be
kept, so they are marked as live when initializing the worklist.

2) Branches and OpUnreachable instructions are marked as live if
  a) the block does not have a merge instruction and another instruction
     in the block is marked as live, or
  b) the merge instruction in the same block is marked as live.

3) Any instruction that is not marked as live is removed.

4) If a terminator is to be removed, an OpUnreachable is added.  This
happens when the entire block is dead, and the block will be removed.
The OpUnreachable is generated to make sure the block still has a
terminator, and is valid.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/4509.
2021-10-29 10:46:43 -04:00
Steven Perron
7c5b17d379
Update passes to handle function declarations (#4599)
Spirv-opt has not had to handle module with function declarations.  This
lead many passes to assume that every function has a body.  This is not
always true.  This commit will modify a number of passes to handle
function declarations.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/4443
2021-10-28 11:54:37 -04:00
Steven Perron
b2ba019bf6
Delete decorations before replaces uses in dead branch elim (#4598)
If we do not delete the decoration before all ReplaceAllUses, the decorations will be transferred to the new id.  This can cause problems.

Fixes #4442.
2021-10-28 10:25:37 -04:00
Steven Perron
3291b6951e
Do not fold snegate feeding sdiv. (#4600)
When the variable value is INT_MIN, we cannot fold the negate into the divide, so we have to turn off that folding rule.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/4487.
2021-10-28 10:02:57 -04:00
Jaebaek Seo
d997c83b10
Add spirv-opt pass to replace descriptor accesses based on variable indices (#4574)
This commit adds a spirv-opt pass to replace accesses to
descriptor array based on variable indices with constant
elements.

Before:
```
%descriptor = OpVariable %_ptr_array_Image Uniform
...
%ac = OpAccessChain %_ptr_Image %descriptor %variable_index
(some image instructions using %ac)
```
After:
```
%descriptor = OpVariable %_ptr_array_Image Uniform
...
OpSwitch %variable_index 0 %case0 1 %case1 ...
...
%case0 = OpLabel
%ac = OpAccessChain %_ptr_Image %descriptor %uint_0
...
%case1 = OpLabel
%ac = OpAccessChain %_ptr_Image %descriptor %uint_1
...
(use OpPhi for value with concrete type)
```
2021-10-26 17:20:58 -04:00
Steven Perron
d78c1c4cd3
Make IsLocalVar in ADCE work at any time. (NFC) (#4595)
Having IsLocalVar work only sometimes is something that could easily
lead to an error.  This change refactors the code so that the function
can be called at any point.  The current implementation was used because
we did not want to do multiple searches to see if a function was an
entry point or if it had a call.  This was maintained by added a cache
that will store of a given function is an entry point with no calls.
2021-10-26 13:24:29 -04:00
David Neto
7326b494d0
opt: set upper bits of spec constant according to spec (#4589)
When setting default value for spec constants, for numeric bit types smaller
than 32 bits, follow the SPIR-V rules for narrow literals:
- signed integers are sign-extended
- otherwise, upper bits are zero.

Followup to #4588
2021-10-21 09:44:54 -04:00
Dave Airlie
f3fbd98ff5
opt/spec_constants: fix bit pattern width checks. (#4588)
* test: add a test to show 8/16-bit

* opt/spec_constants: fix bit pattern width checks.

The input bit patterns are always at least 32-bits, so let the test
pass for 8/16-bit values as well. This shouldn't have any effect on the
64-bit patterns I assume this was introduced for.
2021-10-20 11:53:24 -04:00
Greg Fischer
001604bd4a
Generate constants directly in CreateDebugInlinedAt (#4572)
Do this if Constant or DefUse managers are invalid. Using the
ConstantManager attempts to regenerate the DefUseManager
which is not valid during inlining.
2021-10-19 18:27:16 -06:00
JiaoluAMD
387cae472e
Opt passes should apply to the exported functions (#4554)
This is follow-up to the commit
bd3a271ce3
2021-10-18 13:18:16 -04:00
Greg Fischer
3e6a85303d
Mark DebugInfoNone as live in ADCE when DebugInfo present (#4568)
Otherwise KillInst() tries to generate it when the module is
inconsistent.
2021-10-14 13:29:54 -04:00
David Neto
e6e77dbdfa
Enable OpConstFunctionPointerINTEL outside function (#4576)
According to spec this opcode is a constant instruction - that's it
can appear outside of function bodies.

Co-authored-by: DmitryBushev <dmitry.bushev@intel.com>
2021-10-14 12:21:11 -04:00
Greg Fischer
6dd73728e9
Fix merge-block assertions with debugInfo (#4563)
Fixes DefUse assertions and invalid DebugScope instruction
between OpLoopMerge and OpBranch for included test shader.
2021-10-13 11:42:40 -06:00
David Neto
b46995741b
Avoid bugprone-move-forwarding-reference warning in Clang (#4560)
Use std::forward<T> instead of std::move, on an argument with
rvalue-reference of template-deduced type.

See https://clang.llvm.org/extra/clang-tidy/checks/bugprone-move-forwarding-reference.html

Bug: crbug.com/1134310
2021-10-06 16:50:16 -04:00
Greg Fischer
63a3912326
Fix ConstantManager to not run AnalyzeInstDefUse if DefUse not valid (#4557)
This fixes inlining which has to create constant for DebugInlinedAt for
NonSemantic.Shader.DebugInfo. Also adds regression tests.
2021-10-05 14:55:06 -04:00
Steven Perron
eeb973f502
More ADCE refactoring (#4548)
Split the code that processes the work list into multiple functions.

Move the code to remove the dead instructions in a function to its own function.
2021-10-04 08:33:10 -04:00
Lukas Hermanns
24476c2e32
spirv-opt: Don't eliminate dead members from StructuredBuffer (#4553)
* Don't eliminate dead members from StructuredBuffer as layout(offset) qualifiers cannot be applied to structure fields.

* Traverse arrays when marking structs as fully used.

Co-authored-by: Steven Perron <stevenperron@google.com>
2021-10-01 08:31:40 -04:00
Steven Perron
c3adcb034f
Adce refactor (NFC) (#4547)
* Have ADCE use cfg struct analysis (NFC)

ADCE has a lot of code and variables to keep track of
information that is easily obtains using the Struct
cfg analysis.  Most of this change is to refactor the
code to have small functions to get the information
from the struct cfg analysis.

A few other changes small refactoring changes are
done.

* Factor out work list initialization in ADCE (NFC)

We move the code that will initially populate the work list into its own
function.  We also simplify the code by making use of the struct cfg
analysis.  That way we can reduce the number of tables used to track
information as we traverse the CFG.
2021-09-24 13:21:45 -04:00
Greg Fischer
19dc86c48c
Handle NonSemantic.Shader Debug[No]Line (#4530)
Debug[No]Line are tracked and optimized using the same mechanism that tracks
and optimizes Op[No]Line.

Also:
    - Fix missing DebugScope at top of block.
    - Allow scalar replacement of access chain in DebugDeclare
2021-09-24 10:56:08 -04:00
Greg Fischer
f125452cf8
Fix inst_buff_addr_check to handle struct loads (#4489) 2021-09-23 12:59:38 -04:00
Steven Perron
59f51bb4f8
Fix extract with out-of-bounds index (#4529)
* Fix extract with out-of-bounds index

When folding a OpCompositeExtract that is fed by an
OpCompositeConstruct, we handle and out of bounds
index, but only in the case where the result of the
OpCompostiteConstruct is a struct.  This change
refactors that folding rule and then improves it to
handle an out-of-bounds access when the result of the
OpCompositeConstruct is a vector.
2021-09-20 13:02:47 -04:00
Greg Fischer
1454c95d1b
spirv-opt: Switch from Vulkan.DebugInfo to Shader.DebugInfo (#4493)
Includes:
- Shift to use of spirv-header extinst.nonsemantic.shader grammar.json
- Remove extinst.nonsemantic.vulkan.debuginfo.100.grammar.json
- Enable all optimizations for Shader.DebugInfo

Also fixes scalar replacement to only insert DebugValue after all
OpVariables. This is not necessary for OpenCL.DebugInfo, but it is
for Shader.DebugInfo.

Likewise, fixes Private-to-Local to insert DebugDeclare after all
OpVariables.

Also fixes inlining to handle FunctionDefinition which can show up
after first block if early return processing happens.

Co-authored-by: baldurk <baldurk@baldurk.org>
2021-09-15 14:38:53 -04:00
Greg Fischer
4ac8e5e541
Add preserve_interface mode to aggressive_dead_code_elim (#4520)
This mode is needed by GPU-assisted validation instrumentation which
cannot change the shader entry point interface.
2021-09-15 14:38:34 -04:00
Alastair Donaldson
36ff135341
spirv-opt: Avoid integer overflow during constant folding (#4511)
In SPIR-V, integers use 2s complement representation, so that signed
integer overflow and underflow is well defined. However, the constant
folder was causing overflow / underflow at the C++ level. This change
avoids such overflows by performing constant folding for IAdd, ISub and
IMul in the context of unsigned values, which works because signedness
is irrelevant according to the SPIR-V semantics for these instructions.

Fixes #4510.
2021-09-14 21:09:05 +00:00
Steven Perron
8865b20295
Handle out-of-bounds accesses in VDCE (#4518)
It is possible that other optimization will propagate
a value into an OpCompositeExtract or OpVectorShuffle
instruction that is larger than the vector size.
Vector DCE has to be able to handle it.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/4513.
2021-09-13 09:57:44 -04:00
Jaebaek Seo
0c09258e07
Set threshold for reduce-load-size pass (#4499)
Allow uses to set the threshold for spirv-opt reduce-load-size pass
2021-09-02 10:45:51 -04:00
Steven Perron
bd3a271ce3
Handle exported functions in ADCE (#4495)
ADCE does not handle exported functions.  This was an explicit decision
because we did not believe that the linkage attribute could be used in
shaders, but it can now.  This change has been made.

While fixing this error, I noticed that the OpName for labels is
sometimes removed because the label instructions are not marked
explicitly marked as live.  This has able been fixed.
2021-08-31 12:39:46 -04:00
Jaebaek Seo
57e1d8ebe3
Add spirv-opt convert-to-sampled-image pass (#4340)
convert-to-sampled-image pass converts images and/or samplers with
given pairs of descriptor set and binding to sampled image.

If a pair of an image and a sampler have the same pair of descriptor
set and binding that is one of the given pairs, they will be
converted to a sampled image. In addition, if only an image has the
descriptor set and binding that is one of the given pairs, it will
be converted to a sampled image as well.

For example, when we have

  %a = OpLoad %type_2d_image %texture
  %b = OpLoad %type_sampler %sampler
  %combined = OpSampledImage %type_sampled_image %a %b
  %value = OpImageSampleExplicitLod %v4float %combined ...

1. If %texture and %sampler have the same descriptor set and binding

  %combine_texture_and_sampler = OpVaraible %ptr_type_sampled_image_Uniform
  ...
  %combined = OpLoad %type_sampled_image %combine_texture_and_sampler
  %value = OpImageSampleExplicitLod %v4float %combined ...

2. If %texture and %sampler have different pairs of descriptor set and binding

  %a = OpLoad %type_sampled_image %texture
  %extracted_image = OpImage %type_2d_image %a
  %b = OpLoad %type_sampler %sampler
  %combined = OpSampledImage %type_sampled_image %extracted_image %b
  %value = OpImageSampleExplicitLod %v4float %combined ...
2021-08-18 08:30:48 -04:00
Nicolas Capens
2c829c4155
Fix early-out for Clamp constant folding (#4461)
Only the first two operands were tested for constness, missing the third
one. Since the FoldFPBinaryOp() at the end of FoldClamp1() returns null
when not both of its operands are constant, this doesn't change any
behavior, but it avoids some needless work.

Also the comment for FoldClamp2() was fixed.
2021-08-16 14:11:38 -04:00
Nicolas Capens
869a550d26
Don't fold unsigned divides of an constant and a negation (#4457)
Negating an unsigned constant results in its two's complement which is
still interpreted as unsigned. For example -2u becomes 4294967294u.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/4456
2021-08-16 09:56:05 -04:00
Greg Fischer
de69f32e89
spirv-opt: Add handling of vulkan debug info to DebugInfoManager (#4423)
Co-authored-by: baldurk <baldurk@baldurk.org>
2021-08-10 09:31:17 -04:00
dong-ja
c4c6f2ba5c
spirv-opt: Add dataflow analysis framework (#4402)
This PR adds a generic dataflow analysis framework to SPIRV-opt, with the intent of being used in SPIRV-lint. This may also be useful for SPIRV-opt, as existing ad-hoc analyses can be rewritten to use a common framework, but this is not the target of this PR.
2021-08-09 16:43:36 -04:00
dong-ja
c6422cff33
spirv-opt: Rename ControlDependenceAnalysis::DoesBlockExist to HasBlock (#4412)
Suggested by Jakub as 'DoesBlockExist' was confusing.
2021-07-29 08:30:48 -04:00
Greg Fischer
983ee2313c
spirv-opt: Add specific handling of vulkan debug info differences (#4398)
Co-authored-by: baldurk <baldurk@baldurk.org>
2021-07-28 21:35:32 -04:00
dong-ja
7dadcf9c76
Add control dependence analysis to opt (#4380)
Control dependence analysis constructs a control dependence graph,
representing the conditions for a block's execution relative to the
results of other blocks with conditional branches, etc.
This is an analysis pass that will be useful for the linter and
potentially also useful in opt. Currently it is unused except for the
added unit tests.
2021-07-28 12:44:32 -04:00
Vasyl Teliman
63238d4f2a
Initialize context in opt::Instruction's move constructor (#4397)
Fixes #4396.
2021-07-23 10:09:51 +01:00
Greg Fischer
d9f8925785
spirv-opt: Where possible make code agnostic of opencl/vulkan debuginfo (#4385)
Co-authored-by: baldurk <baldurk@baldurk.org>
2021-07-21 12:04:38 -04:00
Greg Fischer
8966cc2b27
Add common enum for debug info instructions from either opencl or vulkan (#4377)
Co-authored-by: baldurk <baldurk@baldurk.org>
2021-07-16 16:28:14 -04:00
Jaebaek Seo
4baf3affe3
spirv-opt: support SPV_EXT_shader_image_int64 (#4379) 2021-07-14 08:43:35 -04:00
ZHOU He
f9893c4549
spirv-opt: A pass to removed unused input on OpEntryPoint instructions. (#4275)
The new pass will removed interface variable on the OpEntryPoint instruction when they are not statically referenced in the call tree of the entry point.

It can be enabled on the command line using the options `remove-unused-interface-variables`.
2021-06-29 11:33:58 -04:00
Alastair Donaldson
b8587c984a
spirv-reduce: Allow merging unreachable blocks (#4303)
This change allows the reducer to merge together blocks even when they
are unreachable, but keeps the restriction of reachability in place
for the optimizer.

Fixes #4302.
2021-06-28 23:05:30 +01:00
Alastair Donaldson
4fcdc58946
Add IsReachable function to IRContext (#4323)
There was a lot of code in the codebase that would get the dominator
analysis for a function and then use it to check whether a block is
reachable. In the fuzzer, a utility method had been introduced to make
this more concise, but it was not being used consistently.

This change moves the utility method to IRContext, so that it can be
used throughout the codebase, and refactors all existing checks for
block reachability to use the utility method.
2021-06-28 20:00:14 +01:00
Kévin Petit
e065c482c6
Initial support for SPV_KHR_integer_dot_product (#4327)
* Initial support for SPV_KHR_integer_dot_product

- Adds new operand types for packed-vector-format
- Moves ray tracing enums to the end

- PackedVectorFormat is a new optional operand type, so it requires
  special handling in grammar table generation.

- Add SPV_KHR_integer_dot_product to optimizer whitelists.

- Pass-through validation: valid cases pass validation
  Validation errors are not checked.

- Update SPIRV-Headers

Patch by David Neto <dneto@google.com>
Rebase and minor tweaks by Kevin Petit <kevin.petit@arm.com>

Signed-off-by: David Neto <dneto@google.com>
Signed-off-by: Kevin Petit <kevin.petit@arm.com>
Change-Id: Icb41741cb7f0f1063e5541ce25e5ba6c02266d2c

* format fixes

Change-Id: I35c82ec27bded3d1b62373fa6daec3ffd91105a3
2021-06-23 13:32:24 -04:00
alan-baker
4d22f58a81
Support SPV_KHR_subgroup_uniform_control_flow (#4318)
* Support SPV_KHR_subgroup_uniform_control_flow

Covers:
- assembler
- disassembler
- validator
- optimizer (add to whitelists)

* fix copyright

Co-authored-by: David Neto <dneto@google.com>
2021-06-15 10:07:42 -04:00
Ashley Hauck
edc3a24781
Add SPV_KHR_vulkan_memory_model to aggressive_dead_code_elim (#4320) 2021-06-10 08:36:59 -04:00
Ryan Harrison
8b3dc6bbed
Check that valid bitcasted constant was returned (#4311)
This call returns nullptr to indicate errors.

Fixes https://crbug.com/1213365
2021-06-01 09:09:31 -04:00
Greg Fischer
18d45142e7
Fix crash when optimizing shaders with DebugPrintf (#4280)
Fixes #4219
2021-05-13 13:19:56 -04:00
Jaebaek Seo
089d716d25
Fix dangling phi bug from loop-unroll (#4239)
Fix dangling phi bug from loop-unroll

When unrolling the following loop:
```
%const0 = OpConstant ...
%const1 = OpConstant ...
...
%LoopHeader = OpLabel
%phi0 = OpPhi %float %const0 %PreHeader %phi1 %Latch
%phi1 = OpPhi %float %const1 %PreHeader %x    %Latch
...
%LoopBody = OpLabel
%x = OpFSub %float %phi1 %phi0
...
```

the loop-unroll pass sets the value of `%phi0` as `%phi1` for the second
copy of the loop body. For example, the second copy of
`%x = OpFSub %float %phi1 %phi0` will be
`%y = OpFSub %float %x %phi1`.

Since all phi instructions for inductions will are removed after the
loop unrolling, `%phi1` will be a dead dangling phi.

It happens only for the phi values of the first loop iteration. Replacing those
dangling phis with their initial values fixes this issue.

For example, the second copy of `%x = OpFSub %float %phi1 %phi0` should be
`%y = OpFSub %float %x %const1` because the value of `%phi1` from the
first loop iteration is `%const1`.
2021-04-27 16:27:09 -04:00
Jaebaek Seo
07ec4f83c5
Support folding OpBitcast with numeric constants (#4247)
Add constant folding rule for OpBitcast with numeric scalar or vector
constants.
2021-04-27 14:24:46 -04:00
Ben Clayton
9f23457eef
GraphicsRobustAccessPass: Set module_status_.modified (#4167)
When calling `replace_index`.

Fixes: #4166
2021-04-26 17:14:35 +01:00
Greg Fischer
48007a5c7f
Add interpolate legalization pass (#4220)
This pass converts an internal form of GLSLstd450 Interpolate ops
to the externally valid form. The external form takes the lvalue
of the interpolant. The internal form can do a load of the interpolant.
The pass replaces the load with its pointer. The internal form is
generated by glslang and possibly other frontends for HLSL shaders.
The new pass is called as part of HLSL legalization after all
propagation is complete.

Also adds internal interpolate form to pre-legalization validation
2021-03-31 14:26:36 -04:00
Jason Ekstrand
ecc840d30b
Add validation for SPV_EXT_shader_atomic_float_min_max (#4105)
* Add an "extra_defs" parameter to GenerateShaderCode in atomics_test

* Add validation for SPV_EXT_shader_atomic_float_min_max
2021-03-24 08:49:21 -04:00
Jaebaek Seo
79ab273f99
Accept OpImageTexelPointer user in scalar-replacement (#4187)
We have to conduct the scalar replacement for an aggregate with an image
type even when it has OpImageTexelPointer users.
2021-03-16 16:40:51 -04:00
Corentin Wallez
9e93b165c7
Remove usage of std::iterator. (#4171)
This helper class was deprecated in C++17 and some compilers start
warning about it. Replaces usages of std::iterator with manual type
aliases.
2021-03-12 14:00:56 +00:00
Corentin Wallez
4a59fd4763
Fix -Wextra-semi-stmt -Wsuggest-destructor-override -Wdeprecated-copy-dtor (#4164)
* Fix -Wextra-semi-stmt
* Fix -Wsuggest-destructor-override
* Fix -Wdeprecated-copy-dtor
2021-03-09 13:16:43 +00:00
seppala2
ef3290bbea
spirv-opt: Don't call GenerateCopy for mismatched image types (#4126)
Avoid an assertion that will cause some HLSL shader to fail.  They will be legalized by later passes that will do copy propagation.
2021-02-19 10:59:14 -05:00
greg-lunarg
c79edd260c
Generate differentiated error codes for buffer oob checking (#4144)
This allows the GPU-AV layer to differentiate between errors with
uniform buffers versus storage buffers and map these to the relevant
VUIDs.

This is a resubmit of a previously reverted commit. The revert was
done as someone erroneously attempted to build the latest validation
layers with a TOT spirv-tools. The validation layers must be built with
their known-good glslang and its known-good spirv-tools and spirv-headers.
2021-02-11 17:24:04 -05:00
dan sinclair
cfa1dadb1e
Update a few virtuals to overrides. (#4143)
These methods are overriding their base class, so switch to override
from virtual.
2021-02-10 13:21:38 -05:00
Steven Perron
297723d75a
Mark module as modified if convert-to-half removes decorations. (#4127)
* Mark module as modified if convert-to-half removes decorations.

If the convert-to-half pass does not change the body of the function,
but removes decorations, it returns that nothing changed.  This is
incorrect, and will be fixed.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/4117

* Update comment for RemoveDecorationsFrom
2021-01-28 15:53:34 -05:00
Jaebaek Seo
e8bd26e1f8
Set correct scope and line info for DebugValue (#4125)
The existing spirv-opt `DebugInfoManager::AddDebugValueForDecl()` sets
the scope and line info of the new added DebugValue using the scope and
line of DebugDeclare. This is wrong because only a single DebugDeclare
must exist under a scope while we have to add DebugValue for all the
places where the variable's value is updated. Therefore, we have to set
the scope and line of DebugValue based on the places of the variable
updates.

This bug makes
https://github.com/google/amber/blob/main/tests/cases/debugger_hlsl_shadowed_vars.amber
fail. This commit fixes the bug.
2021-01-28 12:57:35 -05:00
Ben Clayton
8383bd5d6f
Migrate all Kokoro build scripts over to use the docker VM image (#4114)
* Work around GCC-9 warning treated as error

```
../source/opt/instruction.h:101:23: error: '*((void*)& operand +32)' may be used uninitialized in this function [-Werror=maybe-uninitialized]
  101 |     uint64_t result = uint64_t(words[0]);
```

* Migrate all Kokoro build scripts over to use the docker VM image

Required updating the NDK SDK and build scripts, as well as the check_copyright for handling 2021.
2021-01-18 13:36:26 -05:00
Ryan Harrison
9150cd441f
Remove WebGPU support (#4108)
Leaves SPV_ENV_WEBGPU_0 enum in place, but marked deprecated, so users
of the library are not broken by an API enum being removed.

Fixes #4101
2021-01-14 16:45:18 -05:00
Jaebaek Seo
cec658c116
Avoid integrity check failures caused by propagating line instructions (#4096)
Propagating the OpLine/OpNoLine to preserve the debug information
through transformations results in integrity check failures because of
the extra line instructions. This commit lets spirv-opt skip the
integrity check when the code contains OpLine or OpNoLine.
2021-01-13 09:08:28 -05:00
dan sinclair
7bbe1a3164
Revert "Generate differentiated error codes for buffer oob checking (#4097)" (#4100)
This reverts commit c32277c0ba.
2021-01-12 11:36:31 -05:00
greg-lunarg
c32277c0ba
Generate differentiated error codes for buffer oob checking (#4097)
This allows the GPU-AV layer to differentiate between errors with
uniform buffers versus storage buffers and map these to the relevant
VUIDs.
2021-01-11 08:42:48 -05:00
Steven Perron
4ed1f4fce9
Fix binding number calculation in desc sroa (#4095)
When there is an array of strutured buffers, desc sroa will only split
the array, but not a struct type in the structured buffer.  However,
the calcualtion of the number of binding a struct requires does not take
this into consideration.  This commit will fix that.
2021-01-06 13:59:04 -05:00
Marijn Suijten
bda102d7a7
opt: Run DCE when SPV_KHR_shader_clock is used (#4049)
Similar to [1] DCE should be ran when this extension is enabled to
prevent unused bindings from showing up (in particular atomic counters
attached to buffers).

[1]: https://github.com/KhronosGroup/SPIRV-Tools/pull/4047
2020-12-07 14:42:25 -05:00
Ehsan
cd05078662
Take new (raytracing) termination instructions into account. (#4050)
* Take new (raytracing) termination instructions into account.

* Remove duplicate function and add unit test.

* Use KHR for symbols in the test.
2020-12-07 10:26:05 -05:00
Ehsan
10e0ae7946
Do run DCE if SPV_KHR_ray_query is used. (#4047) 2020-12-02 18:46:19 -05:00
greg-lunarg
c1d5a045f6
Change ref_analysis to RefAnalysis to follow coding standards. (#4045) 2020-12-01 19:16:49 -05:00
Steven Perron
c502a15f25
Handle 8-bit index in elim dead member (#4043)
The eliminate dead member pass is written assuming that the index to an
OpAccessChain will be a 32-bit integer or 64-bit integer.  That is
changed to work for any width 64-bits or less.

Fixes https://crbug.com/1151727
2020-12-01 14:48:25 -05:00
greg-lunarg
7046c05d2f
Add texel buffer out-of-bounds checking instrumentation (#4038)
This instruments ImageRead, ImageWrite and ImageFetch when applied to
texel buffers.

Also add new (but not yet generated) buffer OOB error codes differentiated
for VUID classification.
2020-12-01 11:28:16 -05:00
Alastair Donaldson
1299436c8f
Reject SPIR-V that applies void to OpUndef, OpCopyObject, OpPhi (#4036)
Fixes #4035.
2020-11-27 16:31:04 +00:00
David Neto
2c458414c0
BuildModule: optionally avoid adding new OpLine instructions (#4033)
* BuildModule: optionally avoid adding new OpLine instructions

Fixes #4029 for my use case

* Fix formatting

* Create last_line_inst_ only if doing extra line tracking
2020-11-25 14:54:32 -05:00
David Neto
a79aa038ec
Remove prototype for unimplemented method (#4031) 2020-11-25 13:47:38 -05:00
David Neto
cd590fa334
Update MeshShadingNV dependencies (and land Ray tracing updates) (#4028)
* Update to final ray tracing extensions

Drop Provisional from ray tracing enums
    sed -ie 's/RayQueryProvisionalKHR/RayQueryKHR/g' **/*
    sed -ie 's/RayTracingProvisionalKHR/RayTracingKHR/g' **/*
Add terminator support for SpvOpIgnoreIntersectionKHR and SpvOpTerminateRayKHR
Update deps for SPIRV-Headers

* Update capability dependencies for MeshShadingNV

Accommodate https://github.com/KhronosGroup/SPIRV-Headers/pull/180

MeshShadingNV: enables PrimitiveId, Layer, and ViewportIndex

Co-authored-by: Daniel Koch <dkoch@nvidia.com>
2020-11-23 12:23:54 -05:00
greg-lunarg
671914c28e
Fix buffer oob instrumentation for matrix refs (#4025)
Fix buffer oob instrumentation for matrix refs.

Matrix stride decoration is not on matrix type but is a member decoration
on the enclosing struct type. Also correctly apply matrix stride depending
on row or column major.
2020-11-18 12:39:15 -05:00
Alastair Donaldson
1f2fcddd39
spirv-opt: Set parent when adding basic block (#4021)
Ensures that the parent of a block is set in Function::AddBasicBlock.
Removes various now unnecessary calls to BasicBlock::SetParent.

Fixes #3912.
2020-11-13 12:33:15 -05:00
Jaebaek Seo
f686518cee
spirv-opt: properly preserve DebugValue indexes operand (#4022)
spirv-opt has a bug that `DebugInfoManager::AddDebugValueWithIndex()` does not
preserve `Indexes` operands of
[DebugValue](https://www.khronos.org/registry/spir-v/specs/unified1/OpenCL.DebugInfo.100.html#DebugValue).
It has to preserve all of those `Indexes` operands, but it preserves only the first index
operand.

This PR removes `DebugInfoManager::AddDebugValueWithIndex()` and lets the spirv-opt
use `DebugInfoManager::AddDebugValueForDecl()`.
`DebugInfoManager::AddDebugValueForDecl()` preserves the Indexes operand correctly.
2020-11-13 12:06:38 -05:00
alan-baker
0c036df288
Add dead function elimination to -O (#4015)
Fixes #4003

Both legalization and size formulae already run dead function
elimination after inlining. This change does the same for performance
passes.
2020-11-05 13:03:45 -05:00
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
Diego Novillo
c74d5523bb
Fix SSA re-writing in the presence of variable pointers. (#4010)
This fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/3873.

In the presence of variable pointers, the reaching definition may be
another pointer.  For example, the following fragment:

 %2 = OpVariable %_ptr_Input_float Input
%11 = OpVariable %_ptr_Function__ptr_Input_float Function
      OpStore %11 %2
%12 = OpLoad %_ptr_Input_float %11
%13 = OpLoad %float %12

corresponds to the pseudo-code:

layout(location = 0) in flat float *%2
float %13;
float *%12;
float **%11;
*%11 = %2;
%12 = *%11;
%13 = *%12;

which ultimately, should correspond to:

%13 = *%2;

During rewriting, the pointer %12 is found to be replaceable by %2.
However, when processing the load %13 = *%12, the type of %12's reaching
definition is another float pointer (%2), instead of a float value.

When this happens, we need to continue looking up the reaching definition
chain until we get to a float value or a non-target var (i.e. a variable
that cannot be SSA replaced, like %2 in this case since it is a function
argument).
2020-11-04 10:23:53 -05:00
Jaebaek Seo
f7da527757
Temporarily add EmptyPass to prevent glslang from failing (#4004)
Removing PropagateLineInfoPass and RedundantLineInfoElimPass from
56d0f5035 makes unit tests of many open source projects fail.
It will happen before submitting this glslang PR
https://github.com/KhronosGroup/glslang/pull/2440. This commit will be
git-reverted after merging the glslang PR.
2020-10-30 18:03:56 -04:00
Junda Liu
82b378d671
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
2020-10-29 16:38:56 -04:00
Jaebaek Seo
56d0f50357
Propagate OpLine to all applied instructions in spirv-opt (#3951)
Based on the OpLine spec, an OpLine instruction must be applied to
the instructions physically following it up to the first occurrence
of the next end of block, the next OpLine instruction, or the next
OpNoLine instruction.

```
OpLine %file 0 0
OpNoLine
OpLine %file 1 1
OpStore %foo %int_1
%value = OpLoad %int %foo
OpLine %file 2 2
```

For the above code, the current spirv-opt keeps three line
instructions `OpLine %file 0 0`, `OpNoLine`, and `OpLine %file 1 1`
in `std::vector<Instruction> dbg_line_insts_` of Instruction class
for `OpStore %foo %int_1`. It does not put any line instruction to
`std::vector<Instruction> dbg_line_insts_` of
`%value = OpLoad %int %foo` even though `OpLine %file 1 1` must be
applied to `%value = OpLoad %int %foo` based on the spec.

This results in the missing line information for
`%value = OpLoad %int %foo` while each spirv-opt pass optimizes the
code. We have to put `OpLine %file 1 1` to
`std::vector<Instruction> dbg_line_insts_` of
both `%value = OpLoad %int %foo` and `OpStore %foo %int_1`.

This commit conducts the line instruction propagation and skips
emitting the eliminated line instructions at the end, which are the same
with PropagateLineInfoPass and RedundantLineInfoElimPass. This
commit removes PropagateLineInfoPass and RedundantLineInfoElimPass.

KhronosGroup/glslang#2440 is a related PR that stop using
PropagateLineInfoPass and RedundantLineInfoElimPass from glslang.
When the code in this PR applied, the glslang tests will pass.
2020-10-29 13:06:30 -04:00
Ben Clayton
7403dfafd8
CMake: Add SPIRV_TOOLS_BUILD_STATIC flag (#3910)
If enabled the following targets will be created:

* `${SPIRV_TOOLS}-static` - `STATIC` library. Has full public symbol visibility.
* `${SPIRV_TOOLS}-shared` - `SHARED` library. Has default-hidden symbol visibility.
* `${SPIRV_TOOLS}`        - will alias to one of above, based on BUILD_SHARED_LIBS.

If disabled the following targets will be created:

* `${SPIRV_TOOLS}`        - either `STATIC` or `SHARED` based on the new `SPIRV_TOOLS_LIBRARY_TYPE` flag. Has full public symbol visibility.
* `${SPIRV_TOOLS}-shared` - `SHARED` library. Has default-hidden symbol visibility.

Defaults to `ON`, matching existing build behavior.

This flag can be used by package maintainers to ensure that all libraries are built as shared objects.
2020-10-29 09:25:26 -04:00
Diego Novillo
cbd1fa6c42
Simplify logic to decide whether CCP modified the IR (#3997)
Simplify logic to decide whether CCP modified the IR.

The previous attempts at fixing this issue relied on marking the IR
changed only when CCP was able to fold an instruction during
propagation (https://github.com/KhronosGroup/SPIRV-Tools/pull/3799,
https://github.com/KhronosGroup/SPIRV-Tools/pull/3732).

Those fixes missed the case described in
https://github.com/KhronosGroup/SPIRV-Tools/issues/3991.  In this case,
the folder never actually succeeds in folding the instruction, but it
does create constants in the process.

Fixed with this change.
2020-10-28 10:18:34 -04:00
Jaebaek Seo
df4198e50e
Add DebugValue for DebugDecl invisible to value assignment (#3973)
For some cases, we have DebugDecl invisible to a value assignment, but
the value assignment information is important i.e., debugger cannot inspect
the variable without the information. For example, a parameter of an inlined
function must have its value assignment i.e., argument passing out of its
function scope. If we simply remove DebugDecl because it is invisible to the
argument passing, we cannot inspec the variable.

This PR
- Adds DebugValue for DebugDecl invisible to a value assignment. We use
the value of the variable in the basic block that contains DebugDecl, which is
found by ssa-rewrite. If the value instruction does not dominate DebugDecl,
we use the value of the variable in the immediate dominator of the basic block.
- Checks the visibility of DebugDecl for Phi value assignment based on the
all value operands of the Phi. Since Phi just references multiple values from
multiple basic blocks, scopes of value operands must be regarded as the scope
of the Phi.
2020-10-27 15:10:08 -04:00
greg-lunarg
34ae8a4757
Fix bounds check instrumentation to handle 16-bit values (#3983) 2020-10-26 09:31:35 -04:00
Jaebaek Seo
fd3948e161
Add DebugValue for function param regardless of scope (#3923)
`DebugInfoManager::AddDebugValueIfVarDeclIsVisible()` adds
OpenCL.DebugInfo.100 DebugValue from DebugDeclare only when the
DebugDeclare is visible to the give scope. It helps us correctly
handle a reference variable e.g.,

{ // scope #1.
  int foo = /* init */;
  { // scope #2.
    int& bar = foo;
    ...

in the above code, we must not propagate DebugValue of `int& bar` for
store instructions in the scope #1 because it is alive only in
the scope #2.

We have an exception: If the given DebugDeclare is used for a function
parameter, `DebugInfoManager::AddDebugValueIfVarDeclIsVisible()` has
to always add DebugValue instruction regardless
of the scope. It is because the initializer (store instruction) for
the function parameter can be out of the function parameter's scope
(the function) in particular when the function was inlined.

Without this change, the function parameter value information always
disappears whenever we run the function inlining pass and
`DebugInfoManager::AddDebugValueIfVarDeclIsVisible()`.
2020-10-16 10:18:41 -04:00
Jaebaek Seo
67f8e2eddc
Debug info preservation in convert-local-access-chains pass (#3835)
1. DebugValue/DebugDeclare references of load/store must not change
the behaviors of the convert-local-access-chains pass
2. We have to properly set the scope and line information of new
instructions made by the convert-local-access-chains pass
2020-10-02 10:45:24 -04:00
Jaebaek Seo
57abfd88c5
Debug info preservation in redundancy-elimination pass (#3839)
* Debug info preservation in redundancy-elimination pass
2020-10-01 09:22:16 -04:00
Jaebaek Seo
e246038364
Debug info preservation in if-conversion pass (#3861)
* Debug info preservation in if-conversion pass
2020-10-01 09:20:27 -04:00
Ryan Harrison
34ef0c3fdc
Fix missed modification flagging (#3814)
Fixes #3813
2020-09-16 19:57:04 -04:00
greg-lunarg
7e28d809c6
Add buffer oob check to bindless instrumentation (#3800) 2020-09-16 09:23:46 -04:00
Diego Novillo
286b3095dd
Properly mark IR changed if instruction folder creates more than one constant. (#3799)
In #3636, I missed that the instruction folder may create more than a
single constant per call.  Since CCP was only checking whether one
constant had been created after folding, it was wrongly thinking that
the IR had not changed.

Fixes #3738.
2020-09-14 09:00:38 -04:00
Alastair Donaldson
ed9863e46e
Favour 'integrity' over 'coherence' as a replacement for 'sanity'. (#3619) 2020-09-10 09:52:21 -04:00
Steven Perron
a187dd58a0
Allow SPV_KHR_8bit_storage extension. (#3780) 2020-09-08 14:13:01 -04:00
Stefano Milizia
1ab52e54ab
spirv-opt: Add function to compute nesting depth of a block (#3771)
This PR adds the NestingDepth function to StructuredCFGAnalysis.
This function, given a block id, returns the number of merge
constructs containing it.

This is needed by spirv-fuzz, but it makes sense to add it to
StructuredCFGAnalaysis, which contains related functionalities.
2020-09-08 12:01:56 +01:00
Jaebaek Seo
8a0ebd40f8
Correctly replace debug lexical scope of instruction (#3718)
When we update OpenCL.DebugInfo.100 lexical scopes e.g., DebugFunction,
we have to replace DebugScope of each instruction that uses the lexical
scope correctly.
2020-08-31 10:05:38 -04:00
Stefano Milizia
7e4948b2a5
Add LoopNestingDepth function to StructuredCFGAnalysis (#3754) 2020-08-27 08:34:46 -04:00
greg-lunarg
bceab9fab4
Do not register DebugFunction for functions optimized away. (#3749) 2020-08-26 23:25:43 -04:00
Jaebaek Seo
e02f178a71
Handle DebugScope in compact-ids pass (#3724)
We have to update OpenCL.DebugInfo.100 DebugScope for instructions if we
change its lexical scope or DebugInlinedAt.
2020-08-26 10:15:36 -04:00
greg-lunarg
2205254cfb
Fix DebugNoScope to not output InlinedAt operand. (#3748) 2020-08-25 23:27:10 -04:00
greg-lunarg
12df3cafee
Fix SSA-rewrite to remove DebugDeclare for variables without loads (#3719) 2020-08-24 15:33:01 -04:00
Steven Perron
3f8501de9e
Add undef for inlined void function (#3720)
It is possible that the result of a void function call is used.  In case
it is used, we need something that still defines its id after inlining.
We use an undef for that purpose.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/3704
2020-08-24 15:08:55 -04:00
Diego Novillo
b79773a35d
CCP should mark IR changed if it created new constants. (#3732)
CCP should mark IR changed if it created new constants.

This fixes #3636.

When CCP is simulating statements, it will sometimes successfully fold
an instruction, which laters switches to varying.  The initial fold of
the instruction may generate a new constant K.

The problem we were running into is when K never gets propagated to the
IR.  Its definition will still exist, so CCP should mark the IR modified
in this case.

In fixing this bug, I noticed that an existing test was suffering from
the same bug.  The change also makes PassTest::SinglePassRunAndMatch()
return the result from the pass, so that we can check that the pass
marks the IR modified in this case.
2020-08-20 16:48:11 -04:00
Jaebaek Seo
3434cb0b00
Let ADCE pass check DebugScope (#3703)
In the existing code, ADCE pass does not check DebugScope of an
instruction when it checks the users of each instruction, which results
in removing OpenCL.Debug.100 instructions that are only used by
DebugScope. This commit lets ADCE pass add DebugScope of an instruction
to the live instruction set when the instruction is added to the live
instruction set.
2020-08-18 09:33:20 -04:00
André Perez
ee7f0c882f
spirv-opt: Implement opt::Function::HasEarlyReturn function (#3711) 2020-08-18 09:31:24 -04:00
alan-baker
b4c4da3e76
Improve non-semantic instruction handling in the optimizer (#3693)
* No longer blindly add global non-semantic info instructions to global
  types and values
  * functions now have a list of non-semantic instructions that succeed
    them in the global scope
  * global non-semantic instructions go in global types and values if
    they appear before any function, otherwise they are attached to the
    immediate function predecessor in the module
* changed ADCE to use the function removal utility
* Modified EliminateFunction to have special handling for non-semantic
  instructions in the global scope
  * non-semantic instructions are moved to an earlier function (or full
    global set) if the function they are attached to is eliminated
  * Added IRContext::KillNonSemanticInfo to remove the tree of
    non-semantic instructions that use an instruction
  * this is used in function elimination
* There is still significant work in the optimizer to handle
  non-semantic instructions fully in the optimizer
2020-08-13 14:54:14 -04:00
Vasyl Teliman
948577c5df
Fix the bug (#3680) 2020-08-13 09:09:57 -04:00
Vasyl Teliman
1435e427da
Fix the bug (#3683) 2020-08-12 13:00:41 -04:00
Jaebaek Seo
f0ca96d12c
Preserve debug info in dead-insert-elim pass (#3652)
When we determine the liveness of an insert, we have to ignore the debug
instruction (it must not have any impact on the decision).
2020-08-12 10:19:37 -04:00
Steven Perron
8e1380996d
Handle no index access chain in local access chain convert (#3678)
* Handle no index access chain in local access chain convert

Fixes #3643
2020-08-10 22:03:02 -04:00
Steven Perron
2990a21926
Avoid using /MP4 for clang on windows. (#3662) 2020-08-10 10:59:24 -04:00
André Perez
3f33a9aa55
spirv-opt: Improve the code of the Instruction class (#3610) 2020-08-05 15:28:05 -04:00
Jaebaek Seo
b78f4b1518
Remove DebugDeclare only for target variables in ssa-rewrite (#3511)
For each local variable, ssa-rewrite should remove its DebugDeclare
if and only if it is replaced by any number of DebugValues for store
and phi instructions.

For example, when we have two variables `a` whose DebugDeclare
will be replaced to DebugValues by ssa-rewrite pass and `b` whose
DebugDeclare will not be replaced, we have to remove only DebugDeclare
for `a`, not `b`.
2020-07-31 10:00:30 -04:00
Jaebaek Seo
ebaefda666
Debug info preservation in loop-unroll pass (#3548)
When we copy the loop body to unroll it, we have to copy its
instructions but DebugDeclare or DebugValue used for the declaration
i.e., DebugValue with Deref must not be copied and only the first block
can contain those instructions.
2020-07-30 12:18:06 -04:00
dan sinclair
a1ea15c902
Update some language usage. (#3611)
This CL updates various bits of language in line with the guidelines
provided by Android
(https://source.android.com/setup/contribute/respectful-code)
2020-07-29 13:50:58 -04:00
Alastair Donaldson
f9b088fe0d
Avoid use of 'sanity' and 'sanity check' in the code base (#3585)
In line with:

  https://source.android.com/setup/contribute/respectful-code

this change uses the terms 'coherence' and 'coherence check' where
'sanity' and 'sanity check' were previously used.
2020-07-28 23:55:02 -04:00
Ben Clayton
6aed7ffbc7
CMake: Enable building with BUILD_SHARED_LIBS=1 (#3490)
Rename the `${SPIRV_TOOLS}` target to `${SPIRV_TOOLS}-static` and alias `${SPIRV_TOOLS}` to either `${SPIRV_TOOLS}-static` or `${SPIRV_TOOLS}-shared` depending on `BUILD_SHARED_LIBS`.

Re-point all internal uses of `${SPIRV_TOOLS}` to `${SPIRV_TOOLS}-static`.

`${SPIRV_TOOLS}-static` is explicitly renamed to just `${SPIRV_TOOLS}` to ensure the name does not change from current behavior.

Build the `SPIRV-Tools-*` libraries as static, as this is what they always were.

Force the external targets `gmock` and `effcee` to be built statically. These either do not support being built as shared libraries, or require special flags.

Issue: #3482
2020-07-27 13:29:07 -04:00
Jaebaek Seo
6a3eb679bd
Preserve debug info in scalar replacement pass (#3461)
1. Set the debug scope and line information for the new replacement
   instructions.
2. Replace DebugDeclare and DebugValue if their OpVariable or value
   operands are replaced by scalars. It uses 'Indexes' operand of
   DebugValue. For example,

   struct S { int a; int b;}
   S foo; // before scalar replacement

   int foo_a; // after scalar replacement
   int foo_b;

   DebugDeclare %dbg_foo %foo %null_expr // before

   DebugValue %dbg_foo %foo_a %Deref_expr 0 // after
   DebugValue %dbg_foo %foo_b %Deref_expr 1 // means Value(foo.members[1]) == Deref(%foo_b)
2020-07-27 13:02:25 -04:00
Jaebaek Seo
7c901a49c9
Preserve OpenCL.DebugInfo.100 through private-to-local pass (#3571)
A debug instruction must not have any impact on the private-to-local
optimization.
2020-07-27 09:27:47 -04:00
alan-baker
f3cec93665
Support SPV_KHR_terminate_invocation (#3568)
Covers:
- assembler
- disassembler
- validator
- optimizer

Co-authored-by: David Neto <dneto@google.com>
2020-07-22 11:45:02 -04:00
Steven Perron
dca2c86bc8
Sink pointer instructions in merge return (#3569)
We cannot create an OpPhi for pointers, so we have to regenerate these
instructions instead.

Fixes #3030
Fixes #3266
2020-07-22 11:10:58 -04:00
greg-lunarg
cf7e922e70
Preserve OpenCL.DebugInfo.100 through elim-dead-code-aggressive (#3542)
Essentially, it marks all DebugInfo instructions in functions (and their operands) as live. It treats DebugDeclare and DebugValue with Deref as loads and so marks Stores of their variables as live.

It marks each DebugGlobalVariables as live except for its variable. After closure, it rechecks if the variable is live. If not, the DebugGlobalVariable instruction's variable operand is set to DebugInfoNone, per the DebugInfo spec.
2020-07-21 16:10:09 -04:00
vkushwaha-nv
e4aebf99fa
Add changes for SPV_EXT_shader_atomic_float (#3562) 2020-07-21 10:31:05 -04:00
Vasyl Teliman
8e0215afe0
spirv-opt: Add support for OpLabel to dominator analysis (#3516)
Fixes #3515.
2020-07-15 12:59:35 +01:00
Jaebaek Seo
4c33fb0d3d
Rewrite KillDebugDeclares() (#3513)
DebugInfoManager::KillDebugDeclares() must erase the variable id
from |var_id_to_dbg_decl_| after killing its DebugDeclare
instructions.
2020-07-14 14:47:16 -04:00
greg-lunarg
282392dda2
Add support to GPU-AV instrumentation for Task and Mesh shaders (#3512) 2020-07-14 11:55:24 -04:00
greg-lunarg
cf8c86a2d9
Preserve OpenCL.DebugInfo.100 through elim-local-single-store (#3498)
This pass basically follows the same process as ssa-rewrite: it adds a DebugValue after each Store and removes the DebugDeclare or DebugValue Deref. It only does this if all instructions that are dependent on the Store are Loads and are replaced.
2020-07-10 15:17:14 -04:00
Jaebaek Seo
a687057a83
Preserve debug info in vector DCE pass (#3497)
This commit lets the vector DCE pass preserve the OpenCL.DebugInfo.100
information properly. When the vector DCE pass determines the liveness
of instructions, the debug instructions must not affect the decision. In
addition, when it kills some instructions, it has to kill DebugValue
instructions that use the killed instructions. When it updates some
composite values to meaningful values (not undef), it has to remove
DebugValue because the value information becomes incorrect.
2020-07-10 10:19:34 -04:00
Jaebaek Seo
94667fbf66
Fix build failure (#3508) 2020-07-09 21:12:21 -04:00
greg-lunarg
44428352ba
Upgrade elim-local-single-block for OpenCL.DebugInfo.100 (#3451)
Creates a DebugValue when removing a store to a local variable.
2020-07-09 17:21:39 -04:00
Jaebaek Seo
f8eddbbe59
Preserve OpenCL.100.DebugInfo in reduce-load-size pass (#3492)
The decision to reduce the load must be not affected by debug
instructions. For example, even when a DebugValue references a
result id of a loaded composite value, this change lets the
reduce-load-size pass reduce the load if the full composite value is not
used anywhere other than the DebugValue.
2020-07-08 16:34:00 -04:00
Jaebaek Seo
6a4da9da42
Debug info preservation in copy-prop-array pass (#3444)
When the pass replaces the local variable `OpVariable` ids to their
corresponding pointers, we have to update operands of DebugValue or
DebugDeclare instructions.
2020-07-06 13:48:12 -04:00
Jaebaek Seo
fc0dc3a9c7
Fix ADCE pass bug for mulitple entries (#3470)
When there are multiple entries and the shader has a variable with
WorkGroup storage class, those multiple entry functions store values to
the variable. Since ADCE pass uses def-use chains to propagate the work
list, some of instructions in the work list are not actually a part of
the currently processed function. As a result, it adds instructions in
other functions and put them in |live_insts_|. However, it does not
have the control flow information for those instructions in other
functions i.e., |block2headerBranch_| and |header2nextHeaderBranch_|.
When it processes those instructions (they are added when it processes a
different function), it skips handling them because they are already in
|live_insts_| and does not check |block2headerBranch_| and
|header2nextHeaderBranch_|, which results in skipping some branches.
Even though those branches are live branches, it considers they are dead
branches.
2020-06-29 13:08:48 -04:00
Jaebaek Seo
efaae24d00
Clear debug information for kill and replacement (#3459)
For many spirv-opt passes such as simplify-instructions pass, we have to
correctly clear the OpenCL.DebugInfo.100 debug information for
KillInst() and ReplaceAllUses(). If we keep some debug information that
disappeared because of KillInst() and ReplaceAllUses(), adding new
DebugValue instructions based on the existing DebugDeclare information
will generate incorrect information. This CL update DebugInfoManager
and IRContext to correctly clear debug information.
2020-06-25 15:48:26 -04:00
Ehsan
7a1af58785
Support OpCompositeExtract pattern in desc_sroa (#3456)
* Support load and extract pattern in desc_sroa.

* Fix typo in comments.

* Load replacement var before use; and added test.

* fix formatting

* Address code review comments.
2020-06-23 12:24:53 -05:00
Jaebaek Seo
d4b9f576eb
[spirv-opt] debug info preservation in ssa-rewrite (#3356)
Add OpenCL.DebugInfo.100 `DebugValue` instructions for store
and phi instructions of local variables to provide the debugger with
the updated values of local variables correctly.
2020-06-19 14:57:43 -04:00
Ehsan
2a1b8c0622
Updated desc_sroa to support flattening structures (#3448)
Not all structures should be flattened.  Code patterns used by DXC are used to create checks for which structures should be flattened.
2020-06-19 14:35:18 -04:00
Steven Perron
545d158a2f
Use structured order to unroll loops. (#3443)
Fixes #3441
2020-06-18 16:00:34 -04:00
Vasyl Teliman
99651228b2
Add RemoveParameter method (#3437) 2020-06-17 10:15:50 -04:00
Vasyl Teliman
57d9e360c6
Fix return type (#3435) 2020-06-17 10:10:06 -04:00
Ehsan
a7112d544b
Eliminate branches with condition of OpConstantNull (#3438) 2020-06-16 13:31:03 -04:00
dan sinclair
52a5f074e9
Update access control lists. (#3433)
This CL updates the access control lists used in SPIRV-Tools to the more
descriptive allow/deny naming.
2020-06-15 13:20:40 -04:00
greg-lunarg
4410272bdd
Remove deprecated interfaces from instrument passes (#3361) 2020-05-21 13:10:42 -04:00
Jaebaek Seo
50b1557886
Preserve debug info in inline pass (#3349)
Handles the OpenCL100Debug extension in inlining.  It preserves the information that is available while also adding the debug inlined at for all of the inlining that it does.
2020-05-21 13:09:43 -04:00
Diego Novillo
4dbe18b0c8
Reject folding comparisons with unfoldable types. (#3370)
Reject folding comparisons with unfoldable types.

Fixes #3343 

When CCP is evaluating an instruction, it was trying to fold a
comparison with 64 bit integers.  This was causing a fold failure later
since the folder still cannot deal with 64 bit integers.
2020-05-21 12:58:08 -04:00