Commit Graph

66 Commits

Author SHA1 Message Date
alan-baker
d35a78db57
Switch SPIRV-Tools to use spirv.hpp11 internally (#4981)
Fixes #4960

* Switches to using enum classes with an underlying type to avoid
  undefined behaviour
2022-11-04 17:27:10 -04:00
alan-baker
7326b967a5
Prevent null pointer from being dereferenced (#4971)
Fixes https://crbug.com/oss-fuzz/48553

* Assign a reflexive dominator if no other dominator can be found using
  forward traversals
  * This prevents a null dereference of a pointer in the sorting of the
    output
2022-10-24 15:16:33 -04:00
Shahbaz Youssefi
3ec6b3698e
spirv-val: Consistently quote ids in messages (#4950)
Half the messages used to output 'id[%name]' and half id[%name].  With
this change, all messages consistently output 'id[%name]'.  Some typos
are also fixed in the process.
2022-09-29 10:03:49 +02:00
alan-baker
05de650371
Use structural reachability in CFG checks (#4849)
Fixes https://crbug.com/oss-fuzz48578

* Adds structural reachability to basic blocks
  * calculated in same manner as reachability, but using structural
    successors
* Change structured CFG validation to use structural reachability
  instead of reachability
* Fix some invalid reducer cases
2022-07-06 17:43:32 -04:00
David Neto
dcee3a5de0
Update validator diagnostics with "structurally dominated" (#4844)
The updated rules in SPIR-V 1.6 Rev2 use structural dominance,
so update the messages to match
2022-07-06 15:10:29 -04:00
alan-baker
286e9c1187
Use structural dominance to validate cfg (#4832)
* Structural dominance introduced in SPIR-V 1.6 rev2
* Changes the structured cfg validation to use structural dominance
  * structural dominance is based on a cfg where merge and continue
    declarations are counted as graph edges
* Basic blocks now track structural predecessors and structural
  successors
* Add validation for entry into a loop
* Fixed an issue with inlining a single block loop
  * The continue target needs to be moved to the latch block
* Simplify the calculation of structured exits
  * no longer requires block depth
* Update many invalid tests
2022-06-29 23:32:20 -04:00
luzpaz
65ecfd1093
Fix various source comment (doxygen) typos (#4680)
Found via `codespell -q 3 -L fo,lod,parm
2022-01-26 15:13:08 -05:00
alan-baker
7d768812e2
Basic support for SPIR-V 1.6 (#4663)
* Basic support for SPIR-V 1.6

* Update SPIRV-Headers deps
* Add new environment enum for SPIR-V 1.6
* Make default environment 1.6 for most tools
* Update tests
* Disallow conditional branch with duplicate labels
* Disallow Dim=Buffer with sampled images
* Do not require the non-semantic extension after SPIR-V 1.5
2021-12-15 14:38:28 -05:00
David Neto
2feb7074d4
Avoid confusing short-circuiting (#3404)
When checking the OpBranchConditional for selection headers,
we intend to register both the true and false targets.
Short circuiting was getting in the way.

Co-authored-by: Steven Perron <stevenperron@google.com>
2021-10-28 15:57:36 -04:00
alan-baker
846b032b53
Fix infinite loop in validation (#4523)
* Fix infinite loop in validation

Fixes https://crbug.com/38548

* Fixes an issue in structured exit checking where an invalid merge
  could result in an infinite traversal

* formatting
2021-09-13 13:19:04 -04:00
alan-baker
912460e46a
Fix infinite loop in GetBlockDepth (#4519)
Fixes #4515

* Sets block depth to 0 if it encountered multiple times and leaves
  finding the real error for other code
2021-09-11 03:27:14 +00:00
alan-baker
c16224c684
Add some missing switch validation (#4507)
Fixes #4506

* Add validation of selector and default operands
2021-09-08 10:09:01 +01:00
alan-baker
010cd289db
Fix continue construct for single block loops (#4277)
Fixes https://crbug.com/tint/793

* When a loop has an empty loop construct, the loop construct and
  continue construct share the same header so don't disallow the loop
  header for the continue construct
2021-05-12 13:01:32 -04:00
alan-baker
939bc02603
Require an OpSelectionMerge before an OpSwitch (#4154)
Fixes #4153

* OpSwitch is required to be preceeded by OpSelectionMerge
* Update newly invalid tests
2021-03-02 15:40:56 -05:00
Ryan Harrison
9150cd441f
Remove WebGPU support (#4108)
Leaves SPV_ENV_WEBGPU_0 enum in place, but marked deprecated, so users
of the library are not broken by an API enum being removed.

Fixes #4101
2021-01-14 16:45:18 -05:00
Alastair Donaldson
1299436c8f
Reject SPIR-V that applies void to OpUndef, OpCopyObject, OpPhi (#4036)
Fixes #4035.
2020-11-27 16:31:04 +00:00
Alastair Donaldson
6fac705e76
spirv-val: Fix validation of OpPhi instructions (#3919)
Fixes #3918.
2020-10-19 17:36:21 +01:00
dan sinclair
a1ea15c902
Update some language usage. (#3611)
This CL updates various bits of language in line with the guidelines
provided by Android
(https://source.android.com/setup/contribute/respectful-code)
2020-07-29 13:50:58 -04:00
alan-baker
7221ccf85e
Fix reachability in the validator (#3541)
Fixes #3529

* Make BasicBlock::reachable() only consider static reachability
* Fix reachability calculation to be independent of block order
* add tests
2020-07-15 21:27:03 -04:00
alan-baker
1346dd5de1
Disallow phis of images, samplers and sampled images (#3246)
* Disallow phis of sampled images always
* Disallow phis of samplers and images for shaders
* Add tests
* Gate check to only occur post-legalization
2020-03-23 16:59:37 -04:00
alan-baker
6729c4a7ce
Fix structured exit validation (#3141)
Fixes #3139

* If the header of the construct is also a merge block, jump to the
associated header instead of the immediate dominator
  * prevents spurious failures from unrelated constructs
* new tests
2020-01-23 18:04:21 -05:00
Kai Burjack
fad92f1e7e Fix typo in validation message (#3122) 2019-12-27 10:47:16 -05: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
alan-baker
2276e59788 Validate that selections are structured (#2962)
* Validate that selections are structured

WIP

* new checks that switch and conditional branch are proceeded by a
selection merge where necessary

* Don't consider unreachable blocks

* Add some tests

* Changed how labels are marked as seen

* Moved check to more appropriate place
* Labels are now marked as seen when there are encountered in a
terminator instead of when the block is checked
* more tests

* more tests

* Method comment

* new test for a bad case
2019-10-11 17:01:30 -04:00
alan-baker
10951a7c9a
Refactor the InstructionPass (#2924)
* move checks to more appropriate locations
  * remove some duplicated checks
* New function to check valid storage classes
* updated tests
2019-09-27 00:06:36 -04:00
alan-baker
aea4e6b1b9 Fix block depth rule priority (#2755)
Fixes #2743

* Continue depth calculation should take precedence over merge calculation
2019-07-23 13:57:44 -04:00
alan-baker
a94ddc267c
Case validation with repeated labels (#2689)
Fixes #2686

* Update validation to handle the default case being mentioned multiple
times
  * new tests
2019-07-23 11:23:32 -04:00
alan-baker
713da30b63 Disallow merge targeting block with OpLoopMerge (#2610)
Fixes #2588

* Add a check that the merge block of OpLoopMerge may not be the block
that contains the OpLoopMerge
  * add a test
2019-05-21 23:02:53 -07:00
alan-baker
60aaafbc70 Allows breaks selection breaks to switches (#2605)
Fixes #2604

* Allow selection constructs to branch to the nearest selection merge
whose header is terminated by an OpSwitch
  * Cleanup break and continue checks generally
  * add tests
2019-05-21 22:49:37 -07:00
alan-baker
ff4feb44b4 Validate construct exits (#2459)
Validate structured exits from constructs

* Add checks that exits from a construct are valid
* Add Construct::IsStructuredExit()
 * uses specific rules for each type of construct
* Added a test and check for #2213
* Adding tests for bad loop and continue exits
* Fix identification of continue block that prevented some selections
from having any blocks
2019-05-16 14:59:30 -07:00
alan-baker
7e7745fce8 Validate loop merge (#2579)
Fixes #2559

* Validate OpLoopMerge including loop controls
  * add tests
  * fix some bad tests
2019-05-15 19:38:41 -04:00
alan-baker
ac878fcbdd
Remove unreachable block validation (#2525)
* Remove the check that blocks terminated by OpUnreachable are not
statically reachable in the CFG
* Updated tests
2019-04-17 18:21:19 -04:00
alan-baker
8129cf2f99
Remove merge assert in block calculation (#2489)
Fixes #2488

* Validator doesn't identify back-edge of the loop, so the merge is
never set
* Construct::blocks() has safe uses of `merge` so the assert can be
removed
* Added a test
2019-04-02 14:37:05 -04:00
alan-baker
320a7de5c9
Validate that OpUnreacahble is not statically reachable (#2473)
* Adds a validator check that ensures no block reachable from the entry
block is terminated by OpUnreachable
* Updated tests
* Added new tests
2019-03-29 10:49:37 -04:00
Ryan Harrison
b12e7338ee
Implement WebGPU specific CFG validation (#2386)
In WebGPU all blocks are required to be reachable, unless they are one of two
specific degenerate cases for merge-block or continue-target. This PR adds in
checking for these conditions.

Fixes #2068
2019-03-08 13:01:09 -05:00
alan-baker
86f6ac086c Add a test for two back-edges in a continue (#2418) 2019-03-05 11:52:02 -05:00
Steven Perron
464111eaef
Remove use of deprecated googletest macro (#2286)
* Remove use of deprecated googletest macro

INSTANTIATE_TEST_CASE_P has been deprecated.  We need to use
INSTANTIATE_TEST_SUITE_P instead.

* Remove extra commas from test suites.
2019-01-29 18:56:52 -05:00
JasperNV
8915a7c8f1 spirv-val: Emit an error when an OpSwitch target is not an OpLabel (#2298)
Fixes #1628.

* spirv-val: Emit an error when an OpBranch target is not an OpLabel
2019-01-24 12:11:49 -05:00
dan sinclair
d835d664bd
[val] Fixup id name output (#2158)
This CL changes the id/name output from the validator to always use a
consistent id[%name] style. This removes the need for getIdOrName. The
name lookup is changed to use the NameMapper so the output is consistent
with what the disassembler will produce.

Fixes #2137
2018-12-03 17:01:30 -05:00
Steven Perron
b407163ef3
Checks for variable pointers (#1976)
In logical addressing mode, we are not allowed to generate variables
pointers.  There is already a check for OpSelect.  However, OpPhi 
and OpPtrAccessChain are not checked to make sure it does not 
generate an variable pointer.  I've added those checks.

Fixes #1957.
2018-10-16 14:57:55 -04:00
alan-baker
bc09f53c96
Fix calculation of case fall through (#1965)
Fixes #1959

* Code erroneously concluded that the target's fall through was itself
* Added a test
2018-10-10 13:25:48 -04:00
alan-baker
fae1e61ab8
Fix bug in construct block calculation (#1964)
Fixes #1960

* Only allows blocks that are dominated by the header
* Fixed a bad loop fusion test
* Added a test derived from the reported bug
2018-10-10 11:14:01 -04:00
Alan Baker
a77bb2e54b Add validation for execution modes
* Check rules from Execution Mode tables, 2.16.2 and the Vulkan
environment spec

* Allows MeshNV execution model with the following execution modes
 * LocalSize, LocalSizeId, OutputPoints and OutputVertices
 * Done to not break their validation
2018-10-02 10:22:23 -04:00
Alan Baker
8cb949ad34 Validate correct opcode uses of OpFunction
Fixes https://crbug.com/873457

* Filed Khronos SPIR-V issue 352
* Updated bad tests
* Added new test
2018-08-14 10:13:06 -04:00
dan sinclair
eda2cfbe12
Cleanup includes. (#1795)
This Cl cleans up the include paths to be relative to the top level
directory. Various include-what-you-use fixes have been added.
2018-08-03 15:06:09 -04:00
dan sinclair
a5a5ea0e2d
Remove using std::<foo> statements. (#1756)
Many of the files have using std::<foo> statements in them, but then the
use of <foo> will be inconsistently std::<foo> or <foo> scattered
through the file. This CL removes all of the using statements and
updates the code to have the required std:: prefix.
2018-08-01 14:58:12 -04:00
dan sinclair
2c5f1b01d8
Update diag() calls in validate_cfg. (#1760)
This CL updates the diag() calls in validate_cfg to provide the
associated instruction. This fixes a couple places where we output the
last line of the file instead of the instruction as the disassembly.
2018-08-01 09:52:16 -04:00
dan sinclair
e70a412609
Move validation files to val/ directory (#1692)
This CL moves the various validate files into the val/ directory with
the rest of the validation infrastructure. This matches how opt/ is
setup with the passes with the infrastructure.
2018-07-11 10:27:34 -04:00
dan sinclair
2cce2c5b97
Move tests into namespaces (#1689)
This CL moves the test into namespaces based on their directories.
2018-07-11 09:24:49 -04:00
dan sinclair
3dad1cda11
Change libspirv to spvtools namespace (#1678)
This CL changes all of the libspirv namespace code to spvtools to match
the rest of the code base.
2018-07-07 09:38:00 -04:00