Commit Graph

294 Commits

Author SHA1 Message Date
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
Paul Thomson
e12087d6c3
spirv-fuzz: fix test (#3845)
Fix test that broke due to a merge.
2020-09-24 19:38:50 +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
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
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
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
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
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
ed9863e46e
Favour 'integrity' over 'coherence' as a replacement for 'sanity'. (#3619) 2020-09-10 09:52:21 -04: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
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
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
Alastair Donaldson
50cf38b8c9
spirv-fuzz: Do not make synonyms of void result ids (#3747)
Fixes #3746.
2020-08-27 09:39:20 +01: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
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
André Perez
4dd122392f
spirv-fuzz: Add words instead of logical operands (#3728)
Fixes #3727.
2020-08-21 11:14:13 +01: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
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
Antoni Karpiński
c20995ef80
spirv-fuzz: Improve code coverage of tests (#3686)
Improves the code coverage of tests for the following transformations:

1. TransformationAddRelaxedDecoration
2. TransformationReplaceCopyMemoryWithLoadStore
3. TransformationReplaceCopyObjectWithStoreLoad
4. TransformationReplaceLoadStoreWithCopyMemory
5. TransformationReplaceAddSubMulWithCarryingExtended
2020-08-14 12:47:21 +01:00
Vasyl Teliman
72ea7bec4a
spirv-fuzz: Support identical predecessors in TransformationPropagateInstructionUp (#3689)
Support identical predecessors in TransformationPropagateInstructionUp.

A basic block may have multiple identical predecessors as follows:

%1 = OpLabel
OpSelectionMerge %2 None
OpBranchConditional %true %2 %2
%2 = OpLabel
...

This case wasn't supported before.
2020-08-14 12:29:36 +01:00
André Perez
df859f77da
spirv-fuzz: Check integer and float width capabilities (#3670)
`TransformationAddTypeFloat` and `TransformationAddTypeInt` did not check whether the required capabilities were present when adding 16-bit, 64-bit, and 8-bit types.

This change adds these checks in the `IsApplicable` method of each transformation.

Fixes #3669.
2020-08-12 22:05:36 +01:00
André Perez
2641d33516
spirv-fuzz: consider additional access chain instructions (#3672)
`TransformationReplaceIdWithSynonym` is careful to avoid replacing id uses that index into a struct with synonyms because the indices must only be `OpConstant` instructions. However, the check only considered `OpAccessChain` instructions, even though the same restriction applies to `OpInBoundsAccessChain`, `OpPtrAccessChain`, etc. 

This change extends the check to include all access chain instructions.

Fixes #3671.
2020-08-12 21:58:53 +01:00
Vasyl Teliman
b7056e7e03
spirv-fuzz: FuzzerPassPropagateInstructionsUp (#3478)
Given an instruction (that may use an OpPhi result from the same block as an input operand), try to clone the instruction into each predecessor block, replacing the input operand with the corresponding OpPhi input operand in each case, if necessary.

Fixes #3458.
2020-08-11 10:24:32 +01:00
Antoni Karpiński
7b2dd11dda
spirv-fuzz: TransformationReplaceAddSubMulWithCarryingExtended (#3598)
Replaces OpIAdd with OpIAddCarry, OpISub with OpISubBorrow, OpIMul with
OpUMulExtended or OpSMulExtended and stores the result into a fresh_id
representing a structure. Extracts the first element of the result into
the original result_id. This value is the same as the result of the
original instruction.

Fixes #3577
2020-08-06 17:30:34 +01:00
André Perez
6d7f34fbfe
spirv-fuzz: Add TransformationMakeVectorOperationDynamic (#3597)
Fixes #3588.
2020-08-06 15:50:18 +01:00
Stefano Milizia
efc85ff661
spirv-fuzz: make outliner pass use additional transformations (#3604)
This PR changes FuzzerPassOutlineFunctions so that it uses some
transformation that make the TransformationOutlineFunction
transformation applicable in more cases. See the discussion in
#3095 for more details.

Fixes #3095.
2020-08-06 12:29:26 +01:00
Vasyl Teliman
0419751b0c
spirv-fuzz: Handle OpPhis in livesafe functions (#3642)
Fixes #3641.
2020-08-05 19:21:37 +01:00
Vasyl Teliman
a10e760596
spirv-fuzz: Handle OpPhi during constant obfuscation (#3640)
Fixes #3639.
2020-08-05 19:17:27 +01:00
Vasyl Teliman
8bc27a1cfb
spirv-fuzz: Remove OpFunctionCall operands in correct order (#3630)
Fixes #3629.
2020-08-04 19:10:21 +01:00
Vasyl Teliman
d9c73ebd9e
spirv-fuzz: Handle capabilities during module donation (#3651)
Fixes #3648.
2020-08-04 17:11:29 +01:00
Vasyl Teliman
9f22236024
spirv-fuzz: Refactor boilerplate in TransformationAddParameter (#3625)
Part of #3534. I forgot to implement this functionality in the original PR.
2020-08-04 15:04:17 +01:00
Vasyl Teliman
92a71657fc
spirv-fuzz: TransformationMoveInstructionDown (#3477)
Swaps an instruction with the next instruction in the block.

Fixes #3457.
2020-08-03 16:45:24 +01:00
Stefano Milizia
2aaa8653da
spirv-fuzz: Transformation to add loop preheader (#3599)
This PR introduces TransformationAddLoopPreheader, which, given
a loop header and enough fresh ids, adds a loop preheader, updating
all the references so that this new block is the only out-of-loop
predecessor of the header, which branches unconditionally to the
header.

See the discussion in #3095.
2020-07-30 20:18:19 +01:00
André Perez
c6e6597c4f
spirv-fuzz: Implement the OpOuterProduct linear algebra case (#3617)
Fixes #3354.
2020-07-29 23:46:56 +01:00
Vasyl Teliman
054f034ea9
spirv-fuzz: Compute corollary facts from OpBitcast (#3538)
Splits #3523 in two parts. This part implements functionality to
compute corollary facts from OpBitcast equation facts.
2020-07-29 22:06:31 +01:00
Vasyl Teliman
863b8e3d3d
spirv-fuzz: Relax type constraints in DataSynonym facts (#3602)
Fixes #3595.
2020-07-29 17:48:01 +01: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
André Perez
150be20d43
spirv-fuzz: Add condition to make functions livesafe (#3587)
Fixes #3162.
2020-07-28 01:01:59 +01:00
André Perez
1dfc6fc7e5
spirv-fuzz: Implement the OpTranspose linear algebra case (#3589)
This PR implements the OpTranspose case for the
replace linear algebra instruction transformation.
2020-07-27 19:19:13 +01:00
Antoni Karpiński
8a5500656e
spirv-fuzz: adds TransformationReplaceLoadStoreWithCopyMemory (#3586)
Adds a transformation that takes a pair of instruction descriptors to
OpLoad and OpStore that have the same intermediate value and replaces
the OpStore with an equivalent OpCopyMemory.

Fixes #3353.
2020-07-27 15:17:04 +01:00
Stefano Milizia
767518e8e1
spirv-fuzz: Relax type checking for int contants (#3573)
Right now, TransformationRecordSynonymousConstants requires the type
ids of two candidate constants to be exactly the same.
This PR adds an exception for integer constants, which can be
considered equivalent even if their signedness is different.
This applies to both integers and vector constants.

The IsApplicable method of ReplaceIdWithSynonym is also updated so
that, in the case of two integer constants which don't have the same
type, they can only be swapped in particular instructions (those
that don't take the signedness into consideration).

Fixes #3536.
2020-07-27 13:34:44 +01:00
Stefano Milizia
f8920bcfab
spirv-fuzz: Generalise transformation access chain (#3546)
This PR generalises TransformationAddAccessChain so that dynamic
indices for non-struct composites (with clamping to ensure that
accesses are in-bound) are allowed.

The transformation will add instructions to clamp any index to
a non-struct composite, regardless of whether it is a constant
or not.

Fixes #3179.
2020-07-27 11:28:12 +01:00
Alastair Donaldson
059ab0819e
spirv-fuzz: Set message consumer in replayer when shrinking (#3591)
Fixes an issue with the shrinker, where the message consumer set for
the shrinker was not being passed on to the replay object that the
shrinker creates.  This meant that messages generated during replay
would cause an exception to be thrown.
2020-07-27 08:11:12 +01:00
Vasyl Teliman
1aaf5c6134
spirv-fuzz: Create a helper in fuzzerutil to reuse function type (#3572)
Fixes #3534.
2020-07-23 18:01:12 +01:00
Vasyl Teliman
89b3bc5a8b
spirv-fuzz: Test usages of IdIsIrrelevant fact (#3578)
Part of #3177.
Fixes #3579.
2020-07-23 17:19:13 +01:00
Antoni Karpiński
9dc1bfa313
spirv-fuzz: adds TransformationReplaceCopyMemoryWithLoadStore (#3575)
Adds a transformation that replaces instruction OpCopyMemory with
loading the source variable to an intermediate value and storing this
value into the target variable of the original OpCopyMemory instruction.

Fixes #3352
2020-07-23 15:14:20 +01:00
Antoni Karpiński
586a12b9d4
spirv-fuzz: adds TransformationReplaceCopyObjectWithStoreLoad (#3567)
Adds a transformation that replaces instruction OpCopyObject with
storing into a new variable and immediately loading this variable to
|result_id| of the original OpCopyObject instruction.

Fixes #3351.
2020-07-23 08:17:45 +01:00
Vasyl Teliman
fe9e5db890
spirv-fuzz: TransformationReplaceParamsWithStruct (#3455)
Fixes #3453.
2020-07-21 21:02:32 +01:00
Stefano Milizia
98395b834a
spirv-fuzz: Extend TransformationRecordSynonymousConstants to allow composite constants (#3537)
Implemented AreEquivalentConstants method to check equivalency of
constants, changing IsApplicable method of
TransformationRecordSynonymousConstants to allow recording equivalence
of composite constants; added some tests to check this.

Tests with arrays and matrices still need to be added.

Fixes #3533.
2020-07-21 12:08:02 +01:00
Vasyl Teliman
8b5ed4448d
spirv-fuzz: Add IdIsIrrelevant fact (#3561)
Part of #3177.
This PR adds a fact to the fact manager.
2020-07-20 20:10:49 +01:00
Antoni Karpiński
0d8fe0fba0
spirv-fuzz: add TransformationAddRelaxedDecoration (#3545)
Add TransformationAddRelaxedDecoration, which adds the RelaxedPrecision decoration to ids of numeric instructions (those yielding 32-bit ints or floats) in dead blocks.

Fixes #3502
2020-07-20 13:13:07 +01:00
Stefano Milizia
de1ff50f28
spirv-fuzz: Assert false in IsApplicable method of TransformationAccessChain (#3528)
… if it is invalid (with null or undefined pointer).

In this case, assert false instead of returning false so that the fuzzer fails.

Fixes #3185.
2020-07-17 12:57:36 +01:00
Vasyl Teliman
680c77fa6c
spirv-fuzz: Add support for OpBitcast to TransformationEquationInstruction (#3523)
Fixes #3514.
2020-07-16 14:07:09 +01:00
Vasyl Teliman
b0206b0f6e
spirv-fuzz: Add support for OpConvert to TransformationEquationInstruction (#3472)
Part of #3440.
2020-07-16 11:59:05 +01:00
Vasyl Teliman
2fa735dc06
spirv-fuzz: Remove TransformationCopyObject (#3531)
Fixes #3509.
2020-07-15 17:37:19 +01:00
Alastair Donaldson
3e7238c68d
spirv-fuzz: Add replay range option (#3535)
This change adds a --replay-range argument to spirv-fuzz that
facilitates applying only a prefix of transformations.
2020-07-15 12:13:23 +01:00
André Perez
3622769785
spirv-fuzz: Fix instruction insertion issue (#3521)
Fixes #3520.
2020-07-14 17:45:52 +01:00
André Perez
91d921e892
spirv-fuzz: Implement the OpMatrixTimesMatrix linear algebra case (#3527)
This PR implements the OpMatrixTimesMatrix case for the
replace linear algebra instruction transformation.
2020-07-14 17:20:09 +01:00
André Perez
c9b254d045
spirv-fuzz: Support adding dead break from back-edge block (#3519)
Fixes #2577.
2020-07-14 12:32:16 +01:00
André Perez
fe4dca5166
Support OpPhi when replacing boolean constant operand (#3518)
Fixes #2902.
2020-07-14 10:27:15 +01:00
Vasyl Teliman
40c3c1cace
spirv-fuzz: TransformationAddSynonyms (#3447)
Part of #3440.
2020-07-12 09:59:08 +01:00
Stefano Milizia
5f8cdd8b45
Implement transformation to record synonymous constants. (#3494)
Adds a fact-only transformation that records that two constants in the module are synonymous.
2020-07-10 14:02:14 +01:00
Vasyl Teliman
de56c34bd6
spirv-fuzz: TransformationReplaceParameterWithGlobal (#3434)
Fixes #3432.
2020-07-09 11:03:49 +01:00
André Perez
11946e640c
Implement the OpMatrixTimesVector linear algebra case (#3500)
This PR implements the OpMatrixTimesVector case for the
replace linear algebra instruction transformation.
2020-07-09 08:56:08 +01:00
André Perez
daa3b47ed4
spirv-fuzz: Add image sample unused components transformation (#3439)
Fixes #3375.
2020-07-08 17:07:04 +01:00
André Perez
2fbeb04b6e
spirv-fuzz: Implement the OpVectorTimesMatrix linear algebra case (#3489)
This PR implements the OpVectorTimesMatrix case for the
replace linear algebra instruction transformation.
2020-07-07 14:29:48 +01:00
Vasyl Teliman
bd2a9ea852
spirv-fuzz: TransformationInvertComparisonOperator (#3475)
Part of #3440.
2020-07-03 17:37:32 +01:00
Vasyl Teliman
2c1ff230c2
Fix regression (#3481)
Fixes #3480.
2020-07-02 10:51:10 +01:00
Vasyl Teliman
fba90d6b0a
spirv-fuzz: Add FuzzerPassAddCopyMemoryInstructions (#3391)
Fixes #3382.
2020-06-30 21:13:05 +01:00
Vasyl Teliman
ab10489a02
spirv-fuzz: Add one parameter at a time (#3469)
Fixes #3467.
Fixes #3468.
2020-06-30 15:20:27 +01:00
André Perez
c3680adbd5
Implement the OpMatrixTimesScalar linear algebra case (#3450)
This PR implements the OpMatrixTimesScalar case for the
replace linear algebra instruction transformation.
2020-06-26 15:54:33 +01:00
Vasyl Teliman
29ba53f2a2
spirv-fuzz: Implement FuzzerPassAddParameters (#3399)
Fixes #3384.
2020-06-23 17:40:44 +01:00
Vasyl Teliman
8e586e46a2
spirv-fuzz: Permute OpPhi instruction operands (#3421)
Fixes #3415.
2020-06-23 15:00:28 +01:00
Vasyl Teliman
33cf7c425a
spirv-fuzz: Refactor variable creation (#3414)
Fixes #3413.
2020-06-19 16:40:18 +01:00
Vasyl Teliman
d5306c8e8f
spirv-fuzz: Swap operands in OpBranchConditional (#3423)
Fixes #3415.
2020-06-19 16:38:52 +01:00
André Perez
12a4fb3bc1
spirv-fuzz: Add replace linear algebra instruction transformation (#3402)
This PR implements a transformation that replaces
a linear algebra instruction with its mathematical definition.
2020-06-16 11:20:51 +01:00
Vasyl Teliman
30bf46dbe0
Fix operand access (#3427)
Fixes #3426.
2020-06-13 00:03:25 +01:00
Vasyl Teliman
e498967098
spirv-fuzz: Add a test (#3238)
Add a test for issue #3237
2020-06-10 14:13:40 +01:00
Vasyl Teliman
c01f826bc6
spirv-fuzz: Add support for OpSpecConstant* (#3373)
Fixes #3371.
2020-06-10 01:01:15 +01:00
Vasyl Teliman
94808bd0f0
spirv-fuzz: Fix regression (#3396)
Fixes #3392.
2020-06-05 12:28:07 +01:00
André Perez
f050cca7ec
spirv-fuzz: Add push id through variable transformation (#3359)
Makes an id synonym by storing an id to a new variable and then
loading it back from that variable.

Fixes #3192.
2020-05-29 16:43:38 +01:00
Vasyl Teliman
2f69ea849a
spirv-fuzz: Remove FuzzerPassAddUsefulConstructs (#3341)
Fixes #3318.
2020-05-19 15:54:55 +01:00
André Perez
a6b0e132ec
Add adjust branch weights transformation (#3336)
In this PR, the classes that represent the adjust branch weights
transformation and fuzzer pass were implemented. This transformation
adjusts the branch weights of a OpBranchConditional instruction.
2020-05-14 11:38:34 +01:00
Alastair Donaldson
a9f2a145e6
spirv-fuzz: Fix to fact manager (#3339)
Reworks the way uniforms with known constants are queried to avoid
unintended side effects to the constant manager.

Fixes #3338.
2020-05-13 22:04:52 +01:00
Alastair Donaldson
2e1d208ed9
spirv-fuzz: Do not allow adding stores to read-only pointers (#3316)
Re-uses IsReadOnlyPointer functionality for the optimizer to make the check
that avoids storing through read-only pointers more thorough.
2020-05-01 02:50:44 +01:00
Alastair Donaldson
f278b467df
spirv-fuzz: Do not outline regions that end with a loop header (#3312)
The outliner would outline regions ending with a loop header, making
the block containing the call to the outlined function serve as the
loop header.  This, however, is incorrect in general, since the whole
outlined function -- rather than just the exit block for the region --
would end up getting called every time the loop would iterate.

This change restricts the outliner so that the last block in a region
cannot be a loop header.
2020-04-28 13:32:06 +01:00
Alastair Donaldson
88faf63ad3
spirv-fuzz: Clamp statically out-of-bounds accesses in code donation (#3315)
It has been resolved that statically out-of-bounds accesses are not
invalid in SPIR-V (they lead to undefind behaviour at runtime but
should not cause a module to be rejected during validation).  This
change tolerates such accesses in donated code, clamping them in-bound
as part of making a function live-safe.
2020-04-27 14:24:54 +01:00
Alastair Donaldson
d158ffe540
spirv-fuzz: Do not replace the Sample argument in OpImageTexelPointer (#3311)
The Sample argument of OpImageTexelPointer is sometimes required to be
a zero constant.  It thus cannot be replaced with a synonym in
general.  This change avoids replacing this argument with a synonym.
2020-04-27 14:23:11 +01:00
Alastair Donaldson
67f4838659
spirv-fuzz: Make handling of synonym facts more efficient (#3301)
The fact manager maintains an equivalence relation on data descriptors
that tracks when one data descriptor could be used in place of
another.  An algorithm to compute the closure of such facts allows
deducing new synonym facts from existing facts.  E.g., for two 2D
vectors u and v it is known that u.x is synonymous with v.x and u.y is
synonymous with v.y, it can be deduced that u and v are synonymous.

The closure computation algorithm is very expensive if we get large
equivalence relations.

This change addresses this in three ways:

- The size of equivalence relations is reduced by limiting the extent
  to which the components of a composite are recursively noted as
  being equivalent, so that when we have large synonymous arrays we do
  not record all array elements as being pairwise equivalent.

- When computing the closure of facts, equivalence classes above a
  certain size are simply skipped (which can lead to missed facts)

- The closure computation is performed less frequently - it is invoked
  explicitly before fuzzer passes that will benefit from data synonym
  facts.  A new transformation is used to control its invocation, so
  that fuzzing and replaying do not get out of sync.

The change also tidies up the order in which some getters are declared
in FuzzerContext.
2020-04-20 19:02:49 +01:00
Alastair Donaldson
ed96301c6c
spirv-fuzz: Fix to outliner (#3302)
Adds an extra condition on when a region can be outlined to avoid the
case where a region ends with a loop head but such that the loop's
continue target is in the region.  (Outlining such a region would mean
that the loop merge is in the original function and the continue target
in the outlined function.)
2020-04-15 11:39:33 +01:00
Alastair Donaldson
c018fc6ae6
spirv-fuzz: Do not outline regions that produce pointer outputs (#3291)
The function outliner uses a struct to return ids that a region
generates and that are used outside that region.  If these ids have
pointer type this would result in a struct with pointer members, which
leads to illegal loading from non-logical pointers if logical
addressing is used.  This change bans that outlining possibility.
2020-04-14 20:22:30 +01:00
Alastair Donaldson
f460cca9dc
spirv-fuzz: Handle OpRuntimeArray when replacing ids with synonyms (#3292)
Provides support for runtime arrays in the code that traverses
composite types when checking applicability of transformations that
replace ids with synonyms.
2020-04-14 20:21:58 +01:00
Alastair Donaldson
2f180468a7
spirv-fuzz: Handle image storage class in donation (#3290)
Demotes the image storage class to Private during donation.  Also
fixes an issue where instructions that depended on non-donated global
values would not be handled properly.
2020-04-14 20:21:33 +01:00
Alastair Donaldson
f82d47003e
spirv-fuzz: Respect rules for OpSampledImage (#3287)
The SPIR-V data rules say that all uses of an OpSampledImage
instruction must be in the same block as the instruction, and highly
restrict those instructions that can consume the result id of an
OpSampledImage.

This adapts the transformations that split blocks and create synonyms
to avoid separating an OpSampledImage use from its definition, and to
avoid synonym-creation instructions such as OpCopyObject consuming an
OpSampledImage result id.
2020-04-14 20:17:42 +01:00
Alastair Donaldson
538512e8e8
spirv-fuzz: Improve the handling of equation facts (#3281)
The management of equation facts suffered from two problems:

(1) The processing of an equation fact required the data descriptors
    used in the equation to be in canonical form.  However, during
    fact processing it can be deduced that certain data descriptors
    are equivalent, causing their equivalence classes to be merged,
    and that could cause previously canonical data descriptors to no
    longer be canonical.

(2) Related to this, if id equations were known about a canonical data
    descriptor dd1, and other id equations known about a different
    canonical data descriptor dd2, the equation facts about these data
    descriptors were not being merged in the event that dd1 and dd2
    were deduced to be equivalent.

This changes solves (1) by not requiring equation facts to be in
canonical form while processing them, but instead always checking
whether (not necessary canonical) data descriptors are equivalent when
looking for corollaries of equation facts, rather than comparing them
using ==.

Problem (2) is solved by adding logic to merge sets of equations when
data descriptors are made equivalent.

In addition, the change also requires elements to be registered in an
equivalence relation before they can be made equivalent, rather than
being added (if not already present) at the point of being made
equivalent.
2020-04-07 17:38:27 +01:00
Alastair Donaldson
183e3242a3
spirv-fuzz: Handle more general SPIR-V in donation (#3280)
This change increases the extent to which arbitrary SPIR-V can be used
by the fuzzer pass that donates modules. It handles the case where
various ingredients (such as types, variables and particular
instructions) cannot be donated by omitting them, and then either
omitting their dependencies or replacing their dependencies with
alternative instructions.

The change pays particular attention to allowing code that manipulates
image types to be handled (by skipping anything image-specific).
2020-04-07 17:37:51 +01:00
Alastair Donaldson
4af38c49bf
spirv-fuzz: Improve support for compute shaders in donation (#3277)
(1) Runtime arrays are turned into fixed-size arrays, by turning
    OpTypeRuntimeArray into OpTypeArray and uses of OpArrayLength into
    uses of the constant used for the length of the fixed-size array.

(2) Atomic instructions are not donated, and uses of their results are
    replaced with uses of constants of the result type.
2020-04-06 16:08:14 +01:00
Alastair Donaldson
e95fbfb1f5
spirv-fuzz: Transformation to add OpConstantNull (#3273)
Adds a transformation for adding OpConstantNull to a module, for
appropriate data types.
2020-04-02 19:25:30 +01:00
Alastair Donaldson
5d491a7ed6
spirv-fuzz: Handle isomorphic types property in composite construction (#3262)
The fuzzer pass that constructs composites had an issue where it would
regard isomorphic but distinct structs (similarly arrays) as being
interchangeable when constructing composites.  This change fixes the
problem by relying less on the type manager.
2020-04-02 18:33:19 +01:00
Alastair Donaldson
8d4261bc44
spirv-fuzz: Introduce TransformationContext (#3272)
Some transformations (e.g. TransformationAddFunction) rely on running
the validator to decide whether the transformation is applicable.  A
recent change allowed spirv-fuzz to take validator options, to cater
for the case where a module should be considered valid under
particular conditions.  However, validation during the checking of
transformations had no access to these validator options.

This change introduced TransformationContext, which currently consists
of a fact manager and a set of validator options, but could in the
future have other fields corresponding to other objects that it is
useful to have access to when applying transformations.  Now, instead
of checking and applying transformations in the context of a
FactManager, a TransformationContext is used.  This gives access to
the fact manager as before, and also access to the validator options
when they are needed.
2020-04-02 15:54:46 +01:00
Alastair Donaldson
2fdea57d19
spirv-fuzz: Add validator options (#3254)
Allows several validator options to be passed to the fuzzer, to be
used when validation is invoked during fuzzing.
2020-04-02 14:37:59 +01:00
Alastair Donaldson
1af1df3b23
spirv-fuzz: Fix vector width issue in 'add equation instructions' pass (#3223)
Fixes #3213.
2020-03-12 10:56:11 +00:00
André Perez Maselco
4c027048d8
spirv-fuzz: Add toggle access chain instruction transformation (#3211)
In this PR, the classes that represent the toggle access chain
instruction transformation and fuzzer pass were implemented. This
transformation toggles the instructions OpAccessChain and
OpInBoundsAccessChain between them.

Fixes #3193.
2020-03-08 22:33:24 +00:00
Vasyl Teliman
533af49812
spirv-fuzz: Add fuzzer pass to permute function parameters (#3212)
Fixes #3194.
2020-03-08 14:27:05 +00:00
Alastair Donaldson
66a682b6a8
spirv-fuzz: Add swap commutable operands transformation (#3205)
In this PR, the classes that represent the swap commutable operands
transformation and the fuzzer pass were implemented.

Fixes #3205.
2020-03-05 08:18:39 +00:00
Alastair Donaldson
044ecc0b2c
spirv-fuzz: Fuzzer pass to add equation instructions (#3202)
This introduces a new fuzzer pass to add instructions to the module
that define equations, and support in the fact manager for recording
equation facts and deducing synonym facts from equation facts.

Initially the only equations that are supported involve OpIAdd,
OpISub, OpSNegate and OpLogicalNot, but there is scope for adding
support for equations over various other operators.
2020-03-04 14:54:08 +00:00
Alastair Donaldson
6c218ec60b
spirv-fuzz: Fuzzer pass that adds access chains (#3182)
This change adds a fuzzer pass that sprinkles access chain
instructions into a module at random. This allows other passes to
have a richer set of pointers available to them, in particular the
passes that add loads and stores.
2020-02-11 23:10:57 +00:00
Alastair Donaldson
77fb303e58
spirv-fuzz: Fuzzer pass to add function calls (#3178)
Adds a fuzzer pass that inserts function calls into the module at
random. Calls from dead blocks can be arbitrary (so long as they do
not introduce recursion), while calls from other blocks can only be to
livesafe functions.

The change fixes some oversights in transformations to replace
constants with uniforms and to obfuscate constants which testing of
this fuzzer pass identified.
2020-02-10 23:22:34 +00:00
Alastair Donaldson
3d4a0dd48f
spirv-fuzz: Ensure that donated variables are always initialized (#3181)
This change ensures that global and local variables donated from other
modules are always initialized at their declaration in the module
being transformed.  This is to help limit issues related to undefined
behaviour that might arise due to accessing uninitialized memory.

The change also introduces some helper functions in fuzzer_util to
make it easier to find the pointee types of pointer types.
2020-02-10 20:10:41 +00:00
Alastair Donaldson
fe10239f92
spirv-fuzz: Add fuzzer passes to add loads/stores (#3176)
This change adds fuzzer passes that sprinkle loads and stores into a
module at random, with stores restricted to occur in either dead
blocks, or to use pointers for which it is known that the pointee
value does not influence the module's overall behaviour.

The change also generalises the VariableValueIsArbitrary fact to
PointeeValueIsIrrelevant, to allow stores through access chains or
object copies of variables whose values are known to be irrelevant.

The change includes some other minor refactorings.
2020-02-06 16:54:34 +00:00
Alastair Donaldson
1f03ac1027
spirv-fuzz: Fuzzer passes to add local and global variables (#3175)
Adds two new fuzzer passes to add variables to a module: one that adds
Private storage class global variables, another that adds Function
storage class local variables.
2020-02-05 21:07:44 +00:00
Alastair Donaldson
b7e0998e3d
spirv-fuzz: Disallow copying of null and undefined pointers (#3172)
If the fuzzer object-copies a pointer we would like to be able to
perform loads from the copy (and stores to it, if its value is known
not to matter).  Undefined and null pointers present a problem here,
so this change disallows copying them.
2020-02-04 11:15:07 +00:00
Alastair Donaldson
1fc7a9ec77
spirv-fuzz: Arbitrary variable facts (#3165)
This change adds a new kind of fact to the fact manager, which records
when a variable (or pointer parameter) refers to an arbitrary value,
so that anything can be stored to it, without affecting the observable
behaviour of the module, and nothing can be guaranteed about values
loaded from it. Donated modules are the current source of such
variables, and other transformations, such as outlining, have been
adapted to propagate these facts appropriately.
2020-01-30 11:25:29 +00:00
Alastair Donaldson
dd3f8d4922
spirv-fuzz: Add outlining test (#3164)
Adds a test to check that we do outline code that uses pointer
parameters.
2020-01-29 17:58:49 +00:00
Alastair Donaldson
521223b70a
spirv-fuzz: Make functions "livesafe" during donation (#3146)
This change allows the generator to (optionally and at random) make
the functions of a module "livesafe" during donation. This involves
introducing a loop limiter variable to each function and gating the
number of total loop iterations for the function using that variable.
It also involves eliminating OpKill and OpUnreachable instructions
(changing them to OpReturn/OpReturnValue), and clamping access chain
indices so that they are always in-bounds.
2020-01-29 15:52:31 +00:00
Alastair Donaldson
ab7ac60f14
spirv-fuzz: Refactoring and type-related fixes (#3144)
This change refactors some code for walking access chain indexes to
make it mirror the structure of other code (to improve readability in
the first instance and potentially enable a future refactoring to
extract common code), and fixes a problem related to module donation
and function types.
2020-01-21 05:59:57 -08:00
Alastair Donaldson
8013d477ae
spirv-fuzz: add dead blocks (#3135)
This adds a new kind of fact to the fact manager that knows whether a
block is dead - i.e. guaranteed to be statically unreachable - and a
new transformation for adding a selection construct to a CFG that
conditionally branches to a fresh, dead block, such that the branch
will never be dynamically taken. Transformations that may create new
blocks ('split block' and 'outline function') are updated to propagate
dead block facts to newly-created blocks where appropriate. A fuzzer
pass randomly adds dead blocks to the module.

Future transformations will be able to exploit the fact that such
blocks are known to be dead.
2020-01-13 22:04:01 +00:00
Alastair Donaldson
31acc78821
spirv-fuzz: Add fuzzer pass to perform module donation (#3117)
This change adds a fuzzer pass that allows code from other SPIR-V
modules to be donated into the module under transformation.  It also
changes the command-line options of the tools so that, in fuzzing
mode, a file must be specified that contains the names of available
donor modules.
2020-01-07 08:39:55 +00:00
Alastair Donaldson
e01bc6d4e8
spirv-fuzz: Always add new globals to entry point interfaces (#3113)
In the context of SPIR-V 1.4 or higher, global variables cannot be
used by an instruction unless they are listed in the interface of all
entry points that might invoke the instruction.  This change
conservatively adds new global variables to the interfaces of all
entry points (if the SPIR-V version is 1.4 or higher).

Issue #3111 notes that a more rigorous approach to entry point
interfaces could be taken in spirv-fuzz, which would allow being less
conservative here.
2019-12-19 21:16:09 +00:00
Alastair Donaldson
dcb7169bbd
spirv-fuzz: Transformation to add a new function to a module (#3114)
This adds a large transformation that can add a new function to a
SPIR-V module.  This paves the way for donation of code from one
module to another.
2019-12-19 21:15:09 +00:00
Alastair Donaldson
2e41d5ece7
spirv-fuzz: Avoid passing access chains as parameters (#3112)
This change prevents the spirv-fuzz function outliner from outlining a
region that uses the result of an OpAccessChain not defined inside the
region.  Such accesses were turning into parameters to the outlined
function, and the result of an OpAccessChain cannot be passed as a
function parameter according to the SPIR-V specification.
2019-12-19 17:34:36 +00:00
Alastair Donaldson
38d7fbaad0
spirv-fuzz: Transformations to add types, constants and variables (#3101)
This change adds several transformations that allow types, constants,
undefined values and global variables to be added to a module.
2019-12-16 23:54:13 +00:00
Alastair Donaldson
96354f5047
spirv-fuzz: Fuzzer pass to merge blocks (#3097)
This change adds a transformation and associated fuzzer pass for
merging adjacent blocks in a module, re-using block merging code from
the optimizer.
2019-12-12 15:27:40 +00:00
Alastair Donaldson
0a2b38d082
spirv-fuzz: function outlining fuzzer pass (#3078)
A new transformation and associated fuzzer pass in spirv-fuzz that
selects single-entry single-exit control flow graph regions and for
each selected region outlines the region into a new function and
replaces the original region with a call to this function.
2019-12-10 14:47:42 +00:00
Alastair Donaldson
983b5b4fcc
spirv-fuzz: Use validator to check break/continue dominance conditions (#3089)
The passes that add dead breaks and continues suffer from the
challenge that a new control flow graph edge can change dominance
information, leading to the potenital for definitions to no longer
dominate their uses.  The attempt at guarding against this was known
to be incomplete.  This change calls on the SPIR-V validator to do the
necessary checking: in deciding whether adding such an edge would be
legitimate, we clone the module, add the edge, and use the validator
to check whether the transformed clone is valid.

This strategy is heavy-weight, and should be used sparingly, but seems
like a good option when the validity of transformations is intricate,
to avoid reimplementing swathes of validation logic in the fuzzer.

Fixes #2919.
2019-12-06 16:38:17 +00:00
Alastair Donaldson
47f3eb4264
spirv-fuzz: Fix invalid tests (#3079)
This change fixes some tests that turned out to be invalid; recent
improvements to the validator in #3068 exposed them as such.
2019-11-29 15:48:13 +00:00
alan-baker
b334829a91 Validate nested constructs (#3068)
* Validate that if a construct contains a header and it's merge is
reachable, the construct also contains the merge
* updated block merging to not merge into the continue
* update inlining to mark the original block of a single block loop as
the continue
* updated some tests
* remove dead code
* rename kBlockTypeHeader to kBlockTypeSelection for clarity
2019-11-27 16:45:57 -05:00
Alastair Donaldson
52e9cc9301
spirv-fuzz: Improve debugging facilities (#3074)
Adds an option to run the validator on the SPIR-V binary after each
fuzzer pass has been applied, to help identify when the fuzzer has
made the module invalid.  Also adds a helper method to allow dumping
of the sequence of transformations that have been applied to a JSON
file.
2019-11-27 18:05:56 +00:00
Alastair Donaldson
041f0a0249
spirv-fuzz: simplify transformation for replacing an id with a synonym (#3020)
Prior to this change, TransformationReplaceIdWithSynonym was designed
to be able to replace an id with some synonymous data descriptor,
possibly necessitating extracting from a composite into a fresh id in
order to get at the synonymous data.  This change simplifies things so
that TransformationReplaceIdWithSynonym just allows one id to be
replaced by another id.  It is the responsibility of the associated
fuzzer pass - FuzzerPassApplyIdSynonyms - to perform the extraction
operations, using e.g. TransformationCompositeExtract.
2019-11-07 16:19:06 +00:00
Alastair Donaldson
dc59b4b075
spirv-fuzz: vector shuffle transformation (#3015)
Inroduces a new transformation that adds a vector shuffle instruction
to the module, with associated facts about how the result vector of
the shuffle relates to the input vectors.

A fuzzer pass to add such transformations is not yet in place.
2019-11-06 17:11:54 +00:00
Alastair Donaldson
3724cfbea8
spirv-fuzz: better computation of data synonym facts (#3010)
When a data synonym fact about two composites is added, data synonym
facts between all sub-components of the composites are also added.

Furthermore, when data synonym facts been all sub-components of two
composites are known, a data synonym fact relating the two composites
is added. Identification of this case is done in a lazy manner, when
questions about data synonym facts are asked.

The change introduces helper methods to get the size of an array type
and the number of elements of a struct type, and fixes
TransformationCompositeExtract to invalidate analyses appropriately.
2019-11-05 16:45:14 +00:00
Alastair Donaldson
fb6bac889e
spirv-fuzz: make equivalence classes deterministic (#3011)
An equivalence relation is computed by traversing the tree of values
rooted at the class's representative. Children were represented by
unordered sets, meaning that the order of values in an equivalence
class could be nondeterministic. This change makes things
deterministic by representing children using a vector.

The path compression optimization employed in the implementation of
the underlying union-find data structure has the potential to change
the order in which elements appear in an equivalence class by changing
the structure of the tree, so the guarantee of determinism is limited
to being a deterministic function of the manner in which the
equivalence relation is updated and inspected.
2019-11-05 15:34:05 +00:00