Commit Graph

2261 Commits

Author SHA1 Message Date
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
sfricke-samsung
ad77ed7a8d
spirv-val: Label standalone Vulkan VUID (#4091) 2021-01-07 09:00:05 -05:00
sfricke-samsung
aa005e8bd4
spirv-val: Add Vulkan decroation VUID (#4090) 2021-01-06 14:30:56 -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
sfricke-samsung
94d1a80159
spirv-val: Add Vulkan FP Mode VUID (#4088) 2021-01-06 12:45:28 -05:00
sfricke-samsung
6d05ed8410
spirv-val: Fix Vulkan image sampled check (#4085)
* Fix SampledType logic
2021-01-06 12:36:13 -05:00
sfricke-samsung
37c03859de
spirv-val: Add Vulkan ForwardPointer VUID (#4089) 2021-01-06 11:26:58 -05:00
sfricke-samsung
d630e5f8c1
spirv-val: Add Vulkan ImageTexelPointer format check (#4087) 2021-01-06 08:51:15 -05:00
sfricke-samsung
1bb80d2778
spirv-val: Add Vulkan Group Operation VUID (#4086) 2021-01-05 09:51:07 -05:00
sfricke-samsung
17ffa89097
spirv-val: Add first StandAlone VUID 04633 (#4077) 2020-12-17 13:51:17 -05:00
sfricke-samsung
8f4b35c332
spirv-val: Add Subgroup VUIDs (#4074) 2020-12-17 08:37:43 -05:00
Alastair Donaldson
4e31fdd4aa
spirv-fuzz: Fix OpPhi handling in DuplicateRegionWithSelection (#4065)
Avoid generating OpPhi on void types, and allow the transformation to
take place on regions that produce pointer and sampled image result
ids if such ids are not used after the region.

Fixes #3787.
2020-12-17 11:45:52 +00:00
David Neto
ad898cb949
validation: validate return type of OpImageRead (#4072)
Vulkan: must be 4-element vector
WebGPU: must be 4-element vector
OpenCL:
- must be scalar float for depth image
- must be 4-element vector otherwise
2020-12-15 12:00:59 -05:00
David Neto
305caff2eb
validation: tighter validation of multisampled images (#4059)
* validation: tighter validation of multisampled images

- if MS=1, then Sample image operand is required
- Sampling operations are not permitted when MS=1

Fixes #4057, #4058

* Fail early for multisampled image for sampling, dref, gather
2020-12-14 14:45:48 -05:00
David Neto
a0370efd58
validate OpTypeImage Sampled values for environemnts (#4064)
Fixes #4063
2020-12-10 17:15:46 -05:00
David Neto
7170218b8d
validate StorageImageMultisampled capability (#4062)
* validate StorageImageMultisampled capability

The StorageImageMultisampled capability is required when declaring
an image type with with Multisampled==1 and it's a storage image (Sampled == 2)

Fixes #4061

* Allow SubpassData with Multisampled and Sampled==2
2020-12-10 10:40:46 -05:00
sfricke-samsung
3b85234542
spirv-val: Add last TessLevelOuter and TessLevelInner VUID (#4055) 2020-12-08 14:38:55 -05:00
sfricke-samsung
171290703a
spirv-val: Add last ClipDistance and CullDistance VUID (#4054) 2020-12-08 14:37:24 -05:00
sfricke-samsung
1a6b4053fa
spirv-val: Add last ViewportIndex and Layer VUID (#4053) 2020-12-08 14:34:51 -05:00
sfricke-samsung
9df5225e67
spirv-val: Add last Position VUID (#4052) 2020-12-08 14:31:40 -05:00
alan-baker
862d44a86e
Allow forward pointer to be used in types generally (#4044)
Fixes #4042

* Allow types to have forward declarations as long as that declaration
  is an OpTypeForwardPointer
2020-12-08 08:46:47 -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
Daniel Koch
32573bb216
Add validation support for the ray tracing built-in variables (#4041)
* Add validation for ray tracing builtins

- Remove existing InstanceId testing that was combined with VertexId in awkward ways.
- Rather than adding a new set of functions for each ray tracing builtin, add
  an error table that maps the builtin ID to the 3 common VUIDs for each builtin
  (I could see this being extended for other builtins in the future).
- add F32 matrix validation function
- augment existing PrimitiveId validation to verify Input storage class for the
  RT stages this is accepted in, and correct the list of stages that it is actually
  accepted in (only Intersection / Any Hit / Closest Hit)

* add testing for ray tracing builtins

- remove exising InstanceId testing as it was tangled in with VertexId in now weird ways
  and combine it with the new tests
- add testing for ray tracing builtins
- builtins accepted in the same stages and of the same types are combined into test functions
- add some new matrix types to the code generator so they can be used for testing
2020-12-01 11:42:37 -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
Alastair Donaldson
b0e22d28f5
spirv-fuzz: Fix facts arising from CompositeConstruct (#4034)
Fixes #4023.
2020-11-25 12:03:05 +00:00
Alastair Donaldson
5ffa320fee
spirv-fuzz: Do not flatten conditionals that create synonyms (#4030)
Fixes #4024.
2020-11-24 20:18:23 +00: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
David Neto
1cda495274
Use less stack space when validating Vulkan builtins (#4019)
Don't pass a constructed string as an argument to
ValidateNotCalledwithExecutionModel. That method is captured via
std::bind and it ends up using lots of stack space.
Instead, pass in:
- a Vulkan validation unique ID as an integer instead,
  (with -1 meaning no VUID), and
- the const char* for the explanator text.
2020-11-11 13:29:28 -05:00
sfricke-samsung
a61d07a727
spirv-val: Fix SPV_KHR_fragment_shading_rate VUID label (#4014)
in 3943 the new tests should have failed, but didn't due to the AnyVUID
check not handling case with trailing whitespace. Added trimming to handle
it as easily might happen again in future
2020-11-05 13:04:47 -05:00
sfricke-samsung
650acb575b
spirv-val: Label Layer and ViewportIndex VUIDs (#4013) 2020-11-05 13:04:07 -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
Alastair Donaldson
02195a029c
spirv-fuzz: Fixes to pass management (#4011) 2020-11-04 10:45:53 +00:00
Alastair Donaldson
bcf5b211db
spirv-fuzz: Add support for reining in rogue fuzzer passes (#3987)
Adds some functions that allow a fuzzer pass to check whether it is
spiralling out of control and exit early.  The fuzzer pass for adding
bit instruction synonyms now uses this.  Also make many methods in
FuzzerContext const.
2020-11-03 16:51:10 +00:00
Vasyl Teliman
7d250ed510
spirv-fuzz: Fix assertion failure in FuzzerPassAddCompositeExtract (#3995) 2020-11-03 15:09:36 +00:00
Vasyl Teliman
f9937bcc83
spirv-fuzz: Fix invalid equation facts (#4009)
Fixes #4008.
2020-11-03 15:06:55 +00:00
Vasyl Teliman
aa6035f1c6
spirv-fuzz: Fix bugs in TransformationFlattenConditionalBranch (#4006)
Fixes #4005.
Fixes #3993.
2020-11-03 15:03:08 +00:00
André Perez
5735576f87
spirv-fuzz: Fix bug related to transformation applicability (#3990)
This PR fixes a bug related to the transformation applicability.
When the OpNot case was implemented, its opcode was not
added to the list of supported bit instructions in IsApplicable.
So, the changes made are the following.

- Add OpNot to the list of supported bit instructions.
- Update the tests.
2020-11-03 10:48:30 +00: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
David Neto
25ee275763
Avoid copying a ref in a loop (#4000)
Avoid triggering a warning from newer Clang, which turns into an error
on macOS.
2020-10-29 09:20:45 -04:00
Sidney Just
5edb328e81
spirv-val: Allow the ViewportIndex and Layer built-ins on SPIR-V 1.5 (#3986)
* spirv-val: Allow the ViewportIndex and Layer built-ins when their corresponding SPIR-V 1.5 capabilities are present
* Added tests for OpCapability ShaderViewportIndex and OpCapability ShaderLayer
2020-10-28 14:05:06 -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
André Perez
abe2eff36f
spirv-fuzz: Add expand vector reduction transformation (#3869)
The following implementations are introduced:

- Transformation and fuzzer pass for expanding vector reduction.
- Unit tests to cover the instructions with different vector sizes.

Fixes #3768.
2020-10-23 14:59:08 +01:00
Vasyl Teliman
99ad4f1e29
spirv-fuzz: Don't replace irrelevant indices in OpAccessChain (#3988)
Part of #3980.
2020-10-23 14:52:22 +01:00
Vasyl Teliman
895dafcc1d
spirv-fuzz: Add FuzzerPassAddCompositeExtract (#3904)
Fixes #3806.
2020-10-23 14:49:50 +01:00
Alastair Donaldson
69f07da41b
spirv-fuzz: Fix mismatch with shrinker step limit (#3985)
Fixes #3984.
2020-10-22 23:23:59 +01:00
Alastair Donaldson
9223493f4d
spirv-fuzz: Fix off-by-one error in replayer (#3982)
Fixes #3981.
2020-10-22 20:07:09 +01:00
Alastair Donaldson
4f5423187d
spirv-fuzz: Get order right for OpSelect arguments (#3974)
Fixes #3948.
2020-10-22 16:05:51 +01:00
Alastair Donaldson
88f7bcb6af
spirv-fuzz: Do not add synonym-creating loops in dead blocks (#3975)
Fixes #3954.
2020-10-22 12:07:49 +01:00
Alastair Donaldson
64eaa9832f
spirv-fuzz: Skip OpTypeSampledImage when propagating up (#3976)
Fixes #3959.
2020-10-22 12:07:17 +01:00
Alastair Donaldson
53f2a69c19
spirv-fuzz: Pass OpUndef in function call if needed (#3978)
Fixes #3977.
2020-10-22 12:06:54 +01:00
Alastair Donaldson
de2c0ba202
spirv-fuzz: Fix off-by-one in TransformationCompositeConstruct (#3979) 2020-10-22 12:06:37 +01:00
Alastair Donaldson
dc4a182282
spirv-fuzz: Tolerate absent ids in data synonym fact management (#3966)
Fixes #3952.
2020-10-22 00:06:53 +01:00
Alastair Donaldson
8496780f57
spirv-fuzz: Fix to id availability (#3971)
Fixes #3958.
2020-10-21 22:52:47 +01:00
Alastair Donaldson
3b7aebca45
spirv-fuzz: Fix operand types (#3962)
Fixes #3945.
Fixes #3946.
2020-10-21 22:41:30 +01:00
Alastair Donaldson
a8d7062fe5
spirv-fuzz: Don't flatten conditional if condition is irrelevant (#3944)
Fixes #3942.
2020-10-21 21:26:59 +01:00
Alastair Donaldson
a3d5378df6
spirv-fuzz: Do not produce OpPhis of type OpTypeSampledImage (#3964)
Also removes some redundant validity checks in tests.

Fixes #3950.
2020-10-21 21:12:19 +01:00
Alastair Donaldson
7edd0525b9
spirv-fuzz: Restrict fuzzer pass to reachable blocks (#3970) 2020-10-21 20:52:58 +01:00
Alastair Donaldson
f03779a1a1
spirv-fuzz: Handle more types when extending OpPhi instructions (#3969)
Fixes #3953.
2020-10-21 20:52:36 +01:00
Alastair Donaldson
c794b70461
spirv-fuzz: Skip early terminator wrappers when merging returns (#3968)
Fixes #3955.
2020-10-21 20:51:10 +01:00
Alastair Donaldson
dc9c6407d6
spirv-fuzz: Avoid irrelevant constants in synonym-creating loops (#3967)
Fixes #3956.
2020-10-21 20:50:45 +01:00
Alastair Donaldson
26954c281e
spirv-fuzz: Skip dead blocks in FuzzerPassAddOpPhiSynonyms (#3965)
Fixes #3949.
2020-10-21 20:49:33 +01:00
Alastair Donaldson
5600fb85b6
spirv-fuzz: Avoid the type manager when looking for struct types (#3963)
Fixes #3947.
2020-10-21 18:28:05 +01:00
Alastair Donaldson
ba15b58862
spirv-fuzz: Fix to TransformationDuplicateRegionWithSelection (#3941)
Also incorporates a few style fixes.

Fixes #3940.
2020-10-20 18:59:53 +01:00
Alastair Donaldson
5984350044
spirv-fuzz: Skip OpFunction when replacing irrelevant ids (#3932)
Fixes #3927.
2020-10-20 18:58:42 +01:00
Alastair Donaldson
8362eae552
spirv-fuzz: Use component-wise selectors when flattening conditional branches (#3921)
Fixes #3920.
2020-10-20 18:57:56 +01:00
Tobski
ebe0ea09f0
Add SPV_EXT_shader_image_int64 (#3852)
* Add SPV_EXT_shader_image_atomic_int64
* Added 64-bit image tests


Co-authored-by: Arkadiusz Sarwa <arkadiusz.sarwa@amd.com>
2020-10-20 11:55:26 -04:00
Tobski
a1d38174b1
Support SPV_KHR_fragment_shading_rate (#3943) 2020-10-20 08:00:13 -04:00
Alastair Donaldson
6fac705e76
spirv-val: Fix validation of OpPhi instructions (#3919)
Fixes #3918.
2020-10-19 17:36:21 +01:00
Alastair Donaldson
b1350659b6
spirv-fuzz: Avoid void struct member when outlining functions (#3936)
Fixes #3935.
2020-10-19 17:34:31 +01:00
Alastair Donaldson
fd0f295da6
spirv-fuzz: Do not allow Block-decorated structs when adding parameters (#3931)
Fixes #3929.
2020-10-19 17:34:04 +01:00
Alastair Donaldson
5d7893b376
spirv-fuzz: Fix to operand id type (#3937)
Fixes #3934.
2020-10-19 17:33:25 +01:00
Alastair Donaldson
cd1d3b6e0c
spirv-fuzz: Handle dead blocks in TransformationEquationInstruction (#3933)
Fixes #3926.
2020-10-19 17:32:56 +01:00
Alastair Donaldson
6cdae9da72
spirv-fuzz: Do not allow sampled image load when flattening conditionals (#3930)
Fixes #3928.
2020-10-19 17:32:26 +01:00
Alastair Donaldson
7e1825a596
spirv-fuzz: Take care of OpPhi instructions when inlining (#3939)
Fixes #3938.
2020-10-19 09:41:01 +01:00
Alastair Donaldson
502e982956
spirv-fuzz: Fix to TransformationInlineFunction (#3913)
This fixes a problem where TransformationInlineFunction could lead to
distinct instructions having identical unique ids. It adds a validity
check to detect this problem in general.

Fixes #3911.
2020-10-16 22:58:09 +01:00
Alastair Donaldson
bf1a11dab7
spirv-fuzz: Wrap early terminators before merging returns (#3925)
Incorporates some other fixes for issues that were brought to light by
adding this functionality.

Fixes #3717.
Fixes #3924.
2020-10-16 19:29:39 +01: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
Alastair Donaldson
dd534e877e
spirv-fuzz: Lower probability of adding bit instruction synonyms (#3917)
Fixes #3914.
2020-10-15 15:20:05 +01:00
Alastair Donaldson
53aeba10cd
spirv-fuzz: Fix handling of OpPhi in FlattenConditionalBranch (#3916)
Fixes #3915.
2020-10-15 14:41:23 +01:00
Alastair Donaldson
5c64374dd6
spirv-fuzz: Avoid creating blocks without parents (#3908)
The validity check during fuzzing and in unit tests is strengthened to
require that every block has its enclosing function as its parent.
TransformationMergeFunctionReturns is fixed so that it ensures parents
are set appropriately.

Fixes #3907.
2020-10-13 19:48:18 +01:00
Alastair Donaldson
57b3723c5c
spirv-fuzz: Do not allow creation of constants of block-decorated structs (#3903)
Fixes #3902.
2020-10-13 18:35:41 +01:00
Alastair Donaldson
12ca825a60
spirv-fuzz: Fixes related to irrelevant ids (#3901)
Fixes #3899.
Fixes #3900.
2020-10-13 18:01:42 +01:00
Alastair Donaldson
2e6cf706ee
spirv-fuzz: Fix to transformation that adds a synonym via a loop (#3898)
Fixes #3897.
2020-10-13 14:26:47 +01:00
Alastair Donaldson
4b884928db
spirv-fuzz: Fix to duplicate region with selection (#3896)
Fixes #3895.
2020-10-13 14:25:43 +01:00
Alastair Donaldson
c2553a315f
spirv-fuzz: Do not expose synonym facts for non-existent ids (#3891)
Fixes #3888.
2020-10-09 07:18:46 +01:00
Alastair Donaldson
3602287858
spirv-fuzz: Do not add synonyms involving irrelevant ids (#3890)
Fixes #3886.
2020-10-08 22:34:39 +01:00
Alastair Donaldson
d52f79122a
spirv-fuzz: Do not replace irrelevant ids that are not in blocks (#3892)
Fixes #3889.
2020-10-08 22:33:46 +01:00
Alastair Donaldson
e022659922
spirv-fuzz: Wrap OpKill and similar in function calls (#3884)
Part of #3717.
2020-10-08 22:33:14 +01:00
dan sinclair
11d5924227
Update val to handle reversed instruction sections. (#3887)
Currently the validator, when checking an instruction is in the correct
section, always advances the current section. This means if we have an
instruction from a previous section we'll end up reporting it as invalid
in a function definition. This error is confusing.

This CL updates the validator to check if the given opcode is from a
previous layout section before advancing the current section. If it is
from a previous layout section an error is emitted.
2020-10-08 13:10:12 -04:00
Alastair Donaldson
fc8264854c
spirv-fuzz: Replace dead-block terminators with OpKill etc. (#3882)
Fixes #3615.
2020-10-06 15:59:05 +01:00
Vasyl Teliman
63cc22d645
spirv-fuzz: TransformationPropagateInstructionDown (#3692)
Fixes #3691.
2020-10-06 13:38:19 +01:00
Alastair Donaldson
65b2a9e814
spirv-fuzz: Transformation to add wrappers for OpKill and similar (#3881)
Part of #3717.
2020-10-06 12:07:56 +01:00
Alastair Donaldson
624b16cd0c
spirv-fuzz: Use overflow ids when duplicating regions (#3878)
Fixes #3786.
2020-10-06 12:07:20 +01:00
Vasyl Teliman
bd0dd9cef1
spirv-fuzz: Fix rvalue references (#3883)
Fixes #3659.
2020-10-06 12:06:53 +01:00
Alastair Donaldson
f151337880
spirv-fuzz: Avoid using block-decorated structs in transformations (#3877)
Fixes #3875.
2020-10-02 20:01:08 +01:00
Alastair Donaldson
0e85530728
spirv-fuzz: Use overflow ids when inlining functions (#3880)
Fixes #3751.
2020-10-02 16:53:54 +01: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
Alastair Donaldson
b920b620ad
spirv-fuzz: Integrate spirv-reduce with shrinker (#3849)
This extends shrinking so that spirv-reduce is employed to simplify
the functions that are added by TransformationAddFunction.
2020-10-02 04:53:12 +01:00
Alastair Donaldson
74a711a76d
spirv-fuzz: Only recommend passes when a pass had an effect (#3863)
Fixes #3817.
2020-10-02 04:48:39 +01:00
Stefano Milizia
fc7860e2db
spirv-fuzz: Merge the return instructions in a function (#3838)
This PR introduces TransformationMergeFunctionReturns, which changes
a function so that it only has one reachable return statement.

Fixes #3655.
2020-10-02 04:45:44 +01: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
Vasyl Teliman
16cc197c8c
spirv-fuzz: Refactor conditions in the fact manager (#3867)
Refactors conditions and names of some methods in the fact manager. Part of #3698.
2020-10-01 11:48:47 +01:00
Vasyl Teliman
615fbe6cbc
spirv-fuzz: TransformationWrapRegionInSelection (#3674)
Fixes #3675.
2020-10-01 09:54:10 +01:00
Alastair Donaldson
f2b8a4ee51
spirv-fuzz: Enable some passes with high probability (#3860)
Fixes #3764.
2020-10-01 09:07:06 +01:00
Alastair Donaldson
50e04f6123
spirv-fuzz: Do not add constants for Block-decorated structs (#3862)
Fixes #3794.
2020-10-01 09:06:36 +01:00
Vasyl Teliman
8edd79ddcc
spirv-fuzz: Fix to FuzzerPassFlattenConditionalBranches (#3865)
Fixes #3864.
2020-10-01 09:06:00 +01:00
Vasyl Teliman
719bade4ff
spirv-fuzz: Fix TransformationRecordSynonymousConstants (#3868)
Fixes #3866.
2020-09-30 17:05:10 +01:00
Alastair Donaldson
009facc978
spirv-fuzz: Fix flatten conditional branch transformation (#3859)
Fixes #3850.
2020-09-30 11:43:40 +01:00
Alastair Donaldson
fcb22ecf0f
spirv-fuzz: Report fresh ids in transformations (#3856)
Adds a virtual method, GetFreshIds(), to Transformation. Every
transformation uses this to indicate which ids in its protobuf message
are fresh ids. This means that when replaying a sequence of
transformations the replayer can obtain a smallest id that is not in
use by the module already and that will not be used by any
transformation by necessity. Ids greater than or equal to this id
can be used as overflow ids.

Fixes #3851.
2020-09-29 22:12:49 +01:00
dan sinclair
c6ca885c0b
[spirv-dis] Add some context comments to disassembly. (#3847)
This CL adds some extra new lines and context comments into the
spirv-dis output format. This CL adds:

 - Blank line and '; Annotations' before decorations
 - Blank line and '; Debug Information' before debug instructions
 - Blank line and '; Types, variables and constants' before type section
 - Blank line and '; Function <name>' before each function.

Issue #788
2020-09-28 10:59:50 -04:00
Maksim Ivanov
446adb05ff
Fix use-after-move in val/validate.cpp (#3848)
Fix a use-after-move (potential) bug found by the
"bugprone-use-after-move" clang-tidy check.

This is part of a Chromium-related effort (see
https://crbug.com/1122844).
2020-09-28 10:49:24 -04:00
Antoni Karpiński
4b07d50cd9
spirv-fuzz: Fix bug in TransformationDuplicateRegionWithSelection (#3819)
The following changes are introduced:

1. Entry block might have more than one predecessor, even if it is not
   a selection/loop merge block. However Apply method asserts that
   there is only one predecessor. Now, IsApplicable method ensures
   that there is only one predecessor.

2. In fuzzer pass we exclude both loop headers and selection headers
as potential exit blocks.

Fixes #3827.
2020-09-26 19:18:41 +01:00
André Perez
fec56146a7
spirv-fuzz: Support OpNot bit instruction case (#3841)
This PR implements the OpNot instruction for the
add bit instruction synonym transformation. In addition,
some code improvements have been made.
2020-09-26 10:42:46 +01:00
Alastair Donaldson
9e17b9d07a
spirv-fuzz: Return IR and transformation context after replay (#3846)
Before this change, the replayer would return a SPIR-V binary. This
did not allow further transforming the resulting module: it would need
to be re-parsed, and the transformation context arising from the
replayed transformations was not available. This change makes it so
that after replay an IR context and transformation context are
returned instead; the IR context can subsequently be turned into a
binary if desired.

This change paves the way for an upcoming PR to integrate spirv-reduce
with the spirv-fuzz shrinker.
2020-09-25 09:58:10 +01:00
Alastair Donaldson
9edeeafdb6
spirv-fuzz: Use unique_ptr<FactManager> in TransformationContext (#3844)
TransformationContext now holds a std::unique_ptr to a FactManager,
rather than a plain pointer. This makes it easier for clients of
TransformationContext to work with heap-allocated instances of
TransformationContext, which is needed in some upcoming work.
2020-09-24 17:28:49 +01:00
Vasyl Teliman
330c72549a
spirv-fuzz: Support dead blocks in TransformationAddSynonym (#3832)
Fixes #3830.
2020-09-24 14:18:07 +01:00
Vasyl Teliman
36185f8b09
spirv-fuzz: Move IRContext parameter into constructor (#3837)
This PR converts IRContext parameter in fact managers into a class field. Part of #3698.
2020-09-24 12:27:59 +01:00
Ryan Harrison
d1bb98fd48
Validate SPIRV Version number when parsing binary header (#3834)
Fixes #3831
2020-09-23 11:59:41 -04:00
Stefano Milizia
67525bded1
spirv-fuzz: Create synonym of int constant using a loop (#3790)
This transformation, given a constant integer (scalar or vector) C,
constants I and S of compatible type and scalar 32-bit integer constant
N, such that C = I - S*N, adds a loop which subtracts S from I, N
times, creating a synonym for C.

The related fuzzer pass randomly chooses constants to which to add
synonyms using this transformation, and the location where they should
be added.

Fixes #3616.
2020-09-23 14:10:02 +01:00
Richard S. Wright Jr
7cc4b4d2ca
Fix compiler error on macOS with XCode12 (#3836) 2020-09-22 19:12:23 -04:00
Vasyl Teliman
5a5b750aaf
spirv-fuzz: Handle OpPhis in TransformationInlineFunction (#3833)
Fixes #3829.
2020-09-22 21:35:56 +01:00
Alastair Donaldson
125b642419
spirv-fuzz: Refactor fuzzer, replayer and shrinker (#3818)
In preparation for some upcoming work on the shrinker, this PR changes
the interfaces of Fuzzer, Replayer and Shrinker so that all data
relevant to each class is provided on construction, meaning that the
"Run" method can become a zero-argument method that returns a status,
transformed binary and sequence of applied transformations via a
struct.

This makes greater use of fields, so that -- especially in Fuzzer --
there is a lot less parameter passing.
2020-09-22 10:07:58 +01:00
Alastair Donaldson
60ce96e2ff
spirv-fuzz: Add pass recommendations (#3757)
This change introduces various strategies for controlling the manner
in which fuzzer passes are applied repeatedly, including infrastructure
to allow fuzzer passes to be recommended based on which passes ran
previously.
2020-09-18 15:51:35 +01:00
Stefano Milizia
2945963cce
spirv-fuzz: Consider all ids from dead blocks irrelevant (#3795)
This PR modifies the FactManager methods IdIsIrrelevant and GetIrrelevantIds so
that an id is always considered irrelevant if it comes from a dead block.

Fixes #3733.
2020-09-18 11:45:02 +01:00
Alastair Donaldson
50ae4c5f44
Fix header guard macros (#3811) 2020-09-18 05:37:30 +01:00
Antoni Karpiński
296e9c7bc8
spirv-fuzz: Fix TransformationDuplicateRegionWithSelection (#3815)
Introduces two changes:

- duplicated_exit_region refers to a correct block, regardless of the order
  of the blocks in the enclosing function.
- Exclude the case where the continue target is the exit block.
2020-09-18 05:36:08 +01:00
sfricke-samsung
937a757f04
spirv-val: Add DeviceIndex (#3812) 2020-09-17 08:27:40 -04:00
Ryan Harrison
34ef0c3fdc
Fix missed modification flagging (#3814)
Fixes #3813
2020-09-16 19:57:04 -04:00
André Perez
748edbf8c1
spirv-fuzz: Use an irrelevant id for the unused components (#3810)
Fixes #3808.
2020-09-16 21:23:32 +01:00
Stefano Milizia
8d49fb2f4d
spirv-fuzz: Improvements to random number generation (#3809)
This PR extends the RandomGenerator interface and fixes the
PseudoRandomGenerator class. It:

- Fixes a problem that made the RandomUint32 of PseudoRandomGenerator
  segfault.
- Adds the RandomUint64 function to RandomGenerator and
  PseudoRandomGenerator.

Fixes #3805.
2020-09-16 15:45:05 +01:00
greg-lunarg
7e28d809c6
Add buffer oob check to bindless instrumentation (#3800) 2020-09-16 09:23:46 -04:00
Vasyl Teliman
8fc504110a
spirv-fuzz: Remove CanFindOrCreateZeroConstant (#3807)
Replace FuzzerPass::CanFindOrCreateZeroConstant with
fuzzerutil::CanCreateConstant.
2020-09-16 14:22:22 +01:00
André Perez
e8ce4355ae
spirv-fuzz: Add bit instruction synonym transformation (#3775)
This PR implements part of the add bit instruction synonym transformation.
For now, the implementation covers the OpBitwiseOr, OpBitwiseXor and
OpBitwiseAnd cases.
2020-09-15 23:36:23 +01:00
Vasyl Teliman
e7c84feda0
spirv-fuzz: Skip unreachable blocks (#3729)
Fixes #3722, fixes #3713, fixes #3714.
2020-09-15 23:35:42 +01:00
Alastair Donaldson
f20b523cb1
Fix build errors (#3804) 2020-09-15 21:02:20 +01:00
Vasyl Teliman
3131686d2e
spirv-fuzz: Handle invalid ids in fact manager (#3742)
Fixes #3741.
2020-09-15 17:03:09 +01:00
Vasyl Teliman
4c239bd81b
spirv-fuzz: Support memory instructions MoveInstructionDown (#3700)
Part of #3605.
2020-09-15 15:04:39 +01:00
Stefano Milizia
1e1c308ded
spirv-fuzz: Pass submanagers to other submanagers when necessary (#3796)
This PR changes the fact manager so that, when calling some of the
functions in submanagers, passes references to other submanagers if
necessary (e.g. to make consistency checks).

In particular:

- DataSynonymAndIdEquationFacts is passed to the AddFactIdIsIrrelevant
  function of IrrelevantValueFacts

- IrrelevantValueFacts is passed to the AddFact functions of
  DataSynonymAndIdEquationFacts

The IRContext is also passed when necessary and the calls to the
corresponding functions in FactManager were updated to be valid and
always use an updated context.

Fixes #3550.
2020-09-15 13:27:14 +01:00
Stefano Milizia
f62357e7b8
spirv-fuzz: Transformation to flatten conditional branch (#3667)
This transformation, given the header of a selection construct with
branching instruction OpBranchConditional, flattens it.
Side-effecting operations such as OpLoad, OpStore and OpFunctionCall
are enclosed within smaller conditionals.
It is applicable if the construct does not contain inner selection
constructs or loops, or atomic or barrier instructions.

The corresponding fuzzer pass looks for selection headers and
tries to flatten them.

Needed for the issue #3544, but it does not fix it completely.
2020-09-15 10:31:01 +01:00
sfricke-samsung
5df9300549
spirv-val: Add BaseInstance, BaseVertex, DrawIndex, and ViewIndex (#3782)
* spirv-val: Add BaseInstance and BaseVertex

* spirv-val: Add DrawIndex

* spirv-val: Add ViewIndex
2020-09-14 10:23:44 -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
Antoni Karpiński
244e6c1be6
spirv-fuzz: Add TransformationDuplicateRegionWithSelection (#3773)
Adds a transformation that inserts a conditional statement with a
boolean expression of arbitrary value and duplicates a given
single-entry, single-exit region, so that it is present in each
conditional branch and will be executed regardless of which branch will
be taken.

Fixes #3614.
2020-09-11 11:48:19 +01:00
Alastair Donaldson
5dcb576b69
spirv-reduce: Support reducing a specific function (#3774)
Motivated by integrating spirv-reduce into spirv-fuzz, so that an
added function can be made smaller during shrinking, this adds support
in spirv-reduce for asking reduction to be restricted to the
instructions of a single specified function.
2020-09-11 06:29:43 +01:00
Alastair Donaldson
de7d57984d
spirv-reduce: Refactoring (#3793)
Avoids the use of "using" in favour of explicit qualification, to be
consistent with spirv-fuzz. Fixes indentation in a TODO comment.
Addresses and removes two existing TODO comments by moving some helper
functionality into reduction_util.

Related issue: #2184.
2020-09-10 22:03:40 +01:00
Alastair Donaldson
ed9863e46e
Favour 'integrity' over 'coherence' as a replacement for 'sanity'. (#3619) 2020-09-10 09:52:21 -04:00
Antoni Karpiński
8743d385f3
spirv-fuzz: Fix header guards in transformations/fuzzer passes (#3784) 2020-09-10 11:07:20 +01:00
Paul Thomson
2de7d3af0c
spirv-fuzz: Add SPIRV_FUZZ_PROTOC_COMMAND (#3789)
Add CMake option SPIRV_FUZZ_PROTOC_COMMAND for overriding the protoc
command. This is needed when cross-compiling, such as when building
for Android.
2020-09-10 08:32:48 +01:00
Paul Thomson
a715b1b405
Improve spirv-fuzz CMake code (#3781)
This change improves spirv-fuzz CMake code to be more compatible with other projects that might want to include spirv-fuzz as a sub-project.

* Add a CMake option for building spirv-fuzz. 
* We now check if protobuf targets are already available. 
* We no longer specify `-DGOOGLE_PROTOBUF_NO_RTTI -DGOOGLE_PROTOBUF_USE_UNALIGNED=0`; a newer version of protobuf does not require this. Note that we probably should have specified this for protobuf targets as well, but this is no longer needed. 
* Updated protobuf version in Kokoro scripts and README.md.
2020-09-09 09:56:32 +01: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
Stefano Milizia
fd05605bef
spirv-fuzz: Transformation to convert OpSelect to conditional branch (#3681)
This transformation takes an OpSelect instruction and replaces it with
a conditional branch, selecting the correct value using an OpPhi
instruction.

Fixes part of the issue #3544.
2020-09-03 10:19:02 +01:00
sfricke-samsung
2c60d16a64
spirv-val: Add Vulkan VUID labels to BuiltIn (#3756)
The Vulkan 1.2.152 headers/spec now include Valid Usage IDs (VUID)
for every BuiltIn. This change adds labeling to help aid tracking
the coverage gap in Vulkan targeted validation. This is done with
a script in the Validation Layers that parses the source for VUID
strings, both that there is an implementation and a test for it.

There are 2 main changes:

1. A VUID string is added where applicable. It is wrapped in a function
that at runtimes checks if Vulkan is the target so that other targets
will not be effected as the output error only changes for Vulkan and
the overhead only occurs if there is an error at all.

2. For unit test, a new parameter value was added to allow make sure
that for each VUID there is a matching test. There are cases where the
same unit test checks multiple VUs via the parameter feature of gtest.
For this, I added a custom gMock Matcher to simply loop over a list
of VUID strings
2020-09-02 14:02:13 -04:00
Vasyl Teliman
c341f7a6cd
spirv-fuzz: Add support for BuiltIn decoration (#3736)
Fixes #3676.
2020-09-02 14:14:58 +01:00
Stefano Milizia
c278dada96
spirv-fuzz: Fix GetIdEquivalenceClasses (#3767)
Pointer (if VariablePointers is enabled) to find sets of potential
synonyms.

However, some instructions with these types cannot be used in an OpPhi:

- OpFunction cannot be used as a value
- OpUndef should not be used, because it yields an undefined value for
  each use
Fixes #3761.
2020-09-02 01:07:59 +01:00
Stefano Milizia
788468408e
spirv-fuzz: Replace id in OpPhi coming from a dead predecessor (#3744)
This transformation takes the id of an OpPhi instruction, of a dead
predecessor of the block containing it and a replacement id of
available to use and of the same type as the OpPhi, and changes
the id in the OpPhi corresponding to the given predecessor.

For example, %id = OpPhi %type %v1 %p1 %v2 %p2
becomes %id = OpPhi %type %v3 %p1 %v2 %p2
if the transformation is given %id, %p1 and %v3, %p1 is a dead block,
%v3 is type type and it is available to use at the end of %p1.

The fuzzer pass randomly decides to apply the transformation to OpPhi
instructions for which at least one of the predecessors is dead

Fixes #3726.
2020-09-02 01:06:38 +01:00
Stefano Milizia
3daabd3212
spirv-fuzz: Transformation to replace the use of an irrelevant id (#3697)
A transformation that replaces the use of an irrelevant id with
another id of the same type.

The related fuzzer pass, for every use of an irrelevant id,
checks whether the id can be replaced in that use by another
id of the same type and randomly decides whether to replace
it.

Fixes #3503.
2020-09-01 16:28:04 +01:00
Vasyl Teliman
d7f078f27d
spirv-fuzz: TransformationMutatePointer (#3737)
Fixes #3624.
2020-09-01 12:45:13 +01:00
Stefano Milizia
43a5186011
spirv-fuzz: Compute interprocedural loop nesting depth of blocks (#3753)
This PR extends CallGraph with functions to return:

- a list of functions in lexicographical order, with respect to
  function calls
- the maximum loop nesting depth that a function can be called from
  (computed interprocedurally, e.g. if foo() calls bar() at depth 2
  and bar() calls baz() at depth 1, the maximum depth of baz() will
  be 3).
2020-09-01 12:23:58 +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
Alastair Donaldson
f428aa39ca
spirv-fuzz: Remove opaque pointer design pattern (#3755)
There's no real need for Fuzzer, Replayer and Shrinker to use the
opaque pointer design pattern.  This change removes it, paving the way
for making some upcoming changes to Fuzzer easier.
2020-08-28 13:30:06 +01:00
Stefano Milizia
08291a3a9e
spirv-fuzz: Create synonym via OpPhi and existing synonyms (#3701)
A transformation that adds new OpPhi instructions to blocks with >=1
predecessors, so that its value depends on previously-defined ids of
the right type, which are all synonymous. This instruction is also
recorded as synonymous to the others.

The related fuzzer pass still needs to be implemented.

Fixes #3592 .
2020-08-27 15:59:54 +01:00
Stefano Milizia
7e4948b2a5
Add LoopNestingDepth function to StructuredCFGAnalysis (#3754) 2020-08-27 08:34:46 -04:00
Alastair Donaldson
50cf38b8c9
spirv-fuzz: Do not make synonyms of void result ids (#3747)
Fixes #3746.
2020-08-27 09:39:20 +01: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
Alastair Donaldson
9e26ae0455
spirv-fuzz: Overflow ids (#3734)
This change adds the notion of "overflow ids", which can be used
during shrinking to facilitate applying transformations that would
otherwise have become inapplicable due to earlier transformations
being removed.
2020-08-26 07:49:42 +01:00
greg-lunarg
2205254cfb
Fix DebugNoScope to not output InlinedAt operand. (#3748) 2020-08-25 23:27:10 -04:00
Vasyl Teliman
230f363e6d
spirv-fuzz: Split the fact manager into multiple files (#3699)
Part of #3698.

This splits various components of the fact manager into multiple files.
2020-08-25 18:11:37 +01:00
André Perez
5adc5ae643
spirv-fuzz: Add inline function transformation (#3517)
Fixes #3505.
2020-08-25 17:28:23 +01:00
Vasyl Teliman
1341b58a86
spirv-fuzz: Fix MaybeGetZeroConstant (#3740)
Fixes #3739.
2020-08-25 09:50:00 +01: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
André Perez
4dd122392f
spirv-fuzz: Add words instead of logical operands (#3728)
Fixes #3727.
2020-08-21 11:14:13 +01: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
Antoni Karpiński
a711c594b8
spirv-fuzz: add FuzzerPassAddCompositeInserts (#3606)
Adds FuzzerPassAddCompositeInserts, which randomly adds new
OpCompositeInsert instructions. Each OpCompositeInsert instruction
yields a copy of an original composite with one subcomponent replaced
with an existing or newly added object. Synonym facts are added for the
unchanged components in the original and added composite, and for the
replaced subcomponent and the object, if possible.

Fixes #2859
2020-08-19 13:56:03 +01:00
Antoni Karpiński
582c276d43
spirv-fuzz: Support pointer types in FuzzerPassAddParameters (#3627)
For FuzzerPassAddParameters, adds pointer types (that have the storage
class Function or Private) to the pool of available types for new
parameters. If there are no variables of the chosen pointer type, it
invokes TransformationAddLocalVariable / TransformationAddGlobalVariable
to add one.

Part of #3403
2020-08-19 11:18:47 +01: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
André Perez
e28436f2b8
spirv-fuzz: Check termination instructions when donating modules (#3710)
The FuzzerPassDonateModules was not checking if the function to donate had
a block with OpKill or OpUnreachable as its termination instruction.

Fixes #3709.
2020-08-17 23:30:07 +01:00
Jack Andersen
1023dd7a04
Fix -Wrange-loop-analysis warning (#3712) 2020-08-17 12:59:36 -04:00
André Perez
82f4bf128a
spirv-fuzz: Check header dominance when adding dead block (#3694)
`TransformationAddDeadBlock` did not check whether the existing block
(that will become a selection header) dominates its successor block (that
will become its merge block).

This change adds the check.

Fixes #3690.
2020-08-17 17:47:13 +01:00
Jaebaek Seo
b8de4f57e9
Allow DebugTypeTemplate for Type operand (#3702)
Some OpenCL.DebugInfo.100 instructions such as DebugGlobalVariable
and DebugLocalVariable have the Type operand. This commit allows them to
use DebugTypeTemplate for the Type operand.
2020-08-16 23:42:59 -04:00