Commit Graph

577 Commits

Author SHA1 Message Date
Jaebaek Seo
5342930f91
Debug info preservation in dead branch elimination (#3425)
* Debug info preservation in dead branch elimination

The DeadBranchElimPass class already handles the OpenCL.DebugInfo.100
instructions correctly. This commit just adds a unit test to make sure
it preserves the information properly.

* Add unit test of ReplaceAllWith for debug instruction
2020-06-18 14:55:45 -04:00
Ehsan
a7112d544b
Eliminate branches with condition of OpConstantNull (#3438) 2020-06-16 13:31:03 -04:00
dan sinclair
52a5f074e9
Update access control lists. (#3433)
This CL updates the access control lists used in SPIRV-Tools to the more
descriptive allow/deny naming.
2020-06-15 13:20:40 -04:00
Jaebaek Seo
5543d5faa9
Debug info preservation in ccp pass (#3420)
* Debug info preservation in ccp pass

For constant propagation, the ccp pass already replaces the result id of
a value with a result id of the corresponding constant value. As a part
of the replacement, it correctly updates the operands of
DebugValue/DebugDeclare as well. Since we do not have to any addition
work other than the ccp pass itself, this commit just adds unit tests to
check the debug information preservation.
2020-06-12 10:54:06 -04:00
Jaebaek Seo
636f449e15
Add tests for merge-return debug info preservation (#3389)
* Add tests for merge-return debug info preservation

* No instruct btw merge and terminator
2020-06-02 10:32:03 -04:00
Jaebaek Seo
50b1557886
Preserve debug info in inline pass (#3349)
Handles the OpenCL100Debug extension in inlining.  It preserves the information that is available while also adding the debug inlined at for all of the inlining that it does.
2020-05-21 13:09:43 -04:00
Diego Novillo
4dbe18b0c8
Reject folding comparisons with unfoldable types. (#3370)
Reject folding comparisons with unfoldable types.

Fixes #3343 

When CCP is evaluating an instruction, it was trying to fold a
comparison with 64 bit integers.  This was causing a fold failure later
since the folder still cannot deal with 64 bit integers.
2020-05-21 12:58:08 -04:00
Jaebaek Seo
2b987c49a4
Handle OpConstantNull in ssa-rewrite (#3362)
ssa-rewrite fails in `MemPass::GetPtr()` when the SPIR-V code contains
`OpLoad` for the result id of `OpConstantNull` because of the out of
index access for an operand to get the base address. This commit fixes
it.

Fixes #3344
2020-05-20 12:00:51 -04:00
Steven Perron
85c7e7956b
Don't register edges twice in merge return (#3350)
Fixes #3267
2020-05-19 10:28:04 -04:00
Steven Perron
bd0a2da946
Revert "Revert "[spirv-opt] refactor inlining pass (#3328)" (#3342)" (#3345)
This reverts commit d4fac3451b.
2020-05-14 10:55:47 -04:00
Steven Perron
d4fac3451b
Revert "[spirv-opt] refactor inlining pass (#3328)" (#3342)
This reverts commit 233246bc9c.
2020-05-13 23:44:19 -04:00
Jaebaek Seo
233246bc9c
[spirv-opt] refactor inlining pass (#3328)
- No longer inline functions with early exits. Merge return can modify them so they can be inlined.
- Otherwise no functional change, should be just refactoring.
2020-05-13 23:17:19 -04:00
Steven Perron
63fa9114a9
Do merge return if the return is not at the end of the function. (#3337)
* Do merge return if the return is not at the end of the function.

We will remove the code in inlining to handle a return in the middle of
a function.  To inline those functions, we need to run merge return to
move the return to the end of the function.
2020-05-12 11:56:16 -04:00
Jaebaek Seo
c8590c18bd
Preserve debug info for wrap-opkill (#3331)
Preserve debug info for wrap-opkill
2020-05-06 12:57:57 -04:00
Alastair Donaldson
49842b88ee
Generalize IsReadOnlyVariable() to apply to pointers (#3325)
Generalizes the IsReadOnlyVariable() method, and related methods, so
that they can be used to ask whether pointer result ids are read-only.

Fixes #3324.
2020-04-30 22:47:20 +01:00
Jaebaek Seo
d0a87194f7
Set DebugScope for termination instructions (#3323)
Many high-level languages like HLSL and GLSL generate termination
instructions such as return and branch from the actual part of the
high-level language code like return and if statements. This commit lets
IrLoader set `DebugScope` for termination instructions.
2020-04-28 09:30:44 -04:00
Jaebaek Seo
42268740c9
Add debug information analysis (#3305)
We need an analysis for OpenCL.DebugInfo.100 extension instructions such
as a map between function id and its DebugFunction. This commit add an
analysis for it.
2020-04-27 15:18:55 -04:00
David Neto
eed48ae479
Add spvtools::opt::Operand::AsLiteralUint64 (#3320) 2020-04-27 09:38:06 -04:00
Steven Perron
7d65bce0bb
Sampled images as read-only storage (#3295)
There are some cases where a variable that is declared as a sampled
image could be read only.  That is when the image type has sampled == 1.

Fixes #3288
2020-04-14 12:58:05 -04:00
Steven Perron
e70d25f6fa
Struct CFG analysus and single block loop (#3293)
Loop headers must be marked as in the continue if the loop header is
also the continue target.

Fixes #3264
2020-04-13 10:08:31 -04:00
Jaebaek Seo
000040e707
Preserve debug info in eliminate-dead-functions (#3251)
* Preserve debug info in eliminate-dead-functions

The elimination of dead functions makes OpFunction operand of
DebugFunction invalid. This commit replaces the operand with
DebugInfoNone.
2020-04-13 09:29:36 -04:00
Steven Perron
34be23373b
Handle more cases in dead member elim (#3289)
* Handle more cases in dead member elim

- Rewrite composite insert and extract operations on SpecConstnatOp.
- Leaves assert for Access chain instructions, which are only allowed
for kernels.
- Other operations do not require any extra code will no longer cause an
assert.

Fixes #3284.
Fixes #3282.
2020-04-09 15:44:20 -04:00
alan-baker
af01d57b5e
Update dominates to check for null nodes (#3271)
* Update dominates to check for null nodes

Fixes #3270
2020-04-02 08:19:54 -04:00
alan-baker
f20c0d7971
Set wrapped kill basic block's parent (#3269)
Fixes #3268

* Set the parent of the basic block for the wrapper function
* Add a test
2020-04-01 12:31:57 -04:00
alan-baker
022da4d0e0
Fix identification of Vulkan images and buffers (#3253)
Fixes #3252

* Image and buffer queries did not account for optional level of
arrayness on the variable
  * new tests
2020-03-25 17:38:24 -04:00
Jaebaek Seo
1c8bda3721
Add data structure for DebugScope, DebugDeclare in spirv-opt (#3183)
When DebugScope is given in SPIR-V, each instruction following the
DebugScope is from the lexical scope pointed by the DebugScope in
the high level language. We add DebugScope struction to keep the
scope information in Instruction class. When ir_loader loads
DebugScope/DebugNoScope, it keeps the scope information in
|last_dbg_scope_| and lets following instructions have that scope
information.

In terms of DebugDeclare/DebugValue, if it is in a function body
but outside of a basic block, we keep it in |debug_insts_in_header_|
of Function class. If it is in a basic block, we keep it as a normal
instruction i.e., in a instruction list of BasicBlock.
2020-03-23 11:01:18 -04:00
David Neto
60104cd974
Add opt::Operand::AsCString and AsString (#3240)
It only works when the operand is a literal string.
2020-03-19 12:44:28 -04:00
Daniel Koch
5a97e3a391
Add support for KHR_ray_{query,tracing} extensions (#3235)
Update validator for SPV_KHR_ray_tracing.

* Added handling for new enum types
* Add SpvScopeShaderCallKHR as a valid scope
* update spirv-headers

Co-authored-by: alelenv <alele@nvidia.com>
Co-authored-by: Torosdagli <ntorosda@amd.com>
Co-authored-by: Tobias Hector <tobias.hector@amd.com>
Co-authored-by: Steven Perron <stevenperron@google.com>
2020-03-17 15:30:19 -04:00
greg-lunarg
1fe9bcc108
Instrument: Debug Printf support (#3215)
Create a pass to instrument OpDebugPrintf instructions.  This pass replaces all OpDebugPrintf instructions with instructions to write a record containing the string id and the all specified values into a special printf output buffer (if space allows). This pass is designed to support the printf validation in the Vulkan validation layers.

Fixes #3210
2020-03-12 09:19:52 -04:00
Diego Novillo
a9624b4d5d
Handle TimeAMD in AmdExtensionToKhrPass. (#3168)
This adds support for replacing TimeAMD with OpReadClockKHR.  The scope
for OpReadClockKHR is fixed to be a subgroup because TimeAMD operates
only on subgroup.
2020-02-03 12:13:32 -05:00
Arseny Kapoulkine
0265a9d4de
Implement constant folding for many transcendentals (#3166)
* Implement constant folding for many transcendentals

This change adds support for folding of sin/cos/tan/asin/acos/atan,
exp/log/exp2/log2, sqrt, atan2 and pow.

The mechanism allows to use any C function to implement folding in the
future; for now I limited the actual additions to the most commonly used
intrinsics in the shaders.

Unary folder had to be tweaked to work with extended instructions - for
extended instructions, constants.size() == 2 and constants[0] ==
nullptr. This adjustment is similar to the one binary folder already
performs.

Fixes #1390.

* Fix Android build

On old versions of Android NDK, we don't get std::exp2/std::log2
because of partial C++11 support.

We do get ::exp2, but not ::log2 so we need to emulate that.
2020-02-03 09:20:47 -05:00
Steven Perron
97f1d485b7 Dead branch elim fix (#3160)
We must treat a branch to the merge node of a switch that is in the
header of a construct as a nested construced.  The original merge
instruction is still needed in that case.
2020-01-28 10:17:43 -05:00
greg-lunarg
e7afeb060e Use dummy switch instead of dummy loop in MergeReturn pass. (#3151)
Fixes #3127
2020-01-24 12:20:14 -05:00
Jaebaek Seo
dd37d73c5e Handle conflict between debug info and existing validation rule (#3104)
* Allow OpExtInst for DebugInfo between secion 9 and 10

Fixes #3086

* Handle spirv-opt errors on DebugInfo Ext

* Add IR Loader test

* Fix ir loader bug

* Handle DebugFunction/DebugTypeMember forward reference

* Add test cases (forward reference to function)

* Support old DebugInfo extension

* Validate local debug info out of function
2020-01-23 17:04:30 -05:00
Jaebaek Seo
f8d7df760c
Fix OpLine bug of merge-blocks pass (#3130)
As explained in #3118, spirv-opt merge-blocks pass causes a
spirv-val error when an OpBranch has an OpLine in front of it.

OpLoopMerge
OpBranch ; Will be killed by merge-blocks pass
OpLabel  ; Will be killed by merge-blocks pass
OpLine   ; will be placed between OpLoopMerge and OpBranch - error!
OpBranch

To fix this issue, this commit moves line info of OpBranch to
OpLoopMerge.

Fixes #3118
2020-01-14 14:35:21 -05:00
David Neto
8aa423930d
Avoid pessimizing std::move (#3124)
Should fix a warning
2019-12-27 12:05:58 -05:00
greg-lunarg
9215c1b7df Fix convert-relax-to-half invalid code (#3099) (#3106) 2019-12-20 21:08:12 -05:00
David Neto
e70b009b0f
Add support for SPV_KHR_non_semantic_info (#3110)
Add support for SPV_KHR_non_semantic_info

This entails a couple of changes:

- Allowing unknown OpExtInstImport that begin with the prefix `NonSemantic.`
- Allowing OpExtInst that reference any of those sets to contain unknown
  ext inst instruction numbers, and assume the format is always a series of IDs
  as guaranteed by the extension.
- Allowing those OpExtInst to appear in the types/variables/constants section.
- Not stripping OpString in the --strip-debug pass, since it may be referenced
  by these non-semantic OpExtInsts.
- Stripping them instead in the --strip-reflect pass.

* Add adjacency validation of non-semantic OpExtInst

- We validate and test that OpExtInst cannot appear before or between
  OpPhi instructions, or before/between OpFunctionParameter
  instructions.

* Change non-semantic extinst type to single value

* Add helper function spvExtInstIsNonSemantic() which will check if the extinst
  set is non-semantic or not, either the unknown generic value or any future
  recognised non-semantic set.

* Add test of a complex non-semantic extinst

* Use DefUseManager in StripDebugInfoPass to strip some OpStrings

* Any OpString used by a non-semantic instruction cannot be stripped, all others
  can so we search for uses to see if each string can be removed.
* We only do this if the non-semantic debug info extension is enabled, otherwise
  all strings can be trivially removed.

* Silence -Winconsistent-missing-override in protobufs
2019-12-18 18:10:29 -05:00
greg-lunarg
fccbc00aca Make Instrumentation format version 2 the default (Step 1) (#3096)
* Make Instrumentation format version 2 the default (Step 1)

Add new interfaces without version number argument. Remove version 1
logic and tests. Version interfaces will be removed in step 2 after
layers have transitioned to new interface.

* Add error messages to InstrumentPass().
2019-12-16 14:18:47 -05:00
Steven Perron
00ca4e5bdf
Don't crash when folding construct of empty struct (#3092)
* Don't crash when folding construct of empty struct

An OpCompositeConstruct of an empty struct will be folded to a constant
under normal circumstances.  However, if the id limit has been reached
and the constant cannot be generated, then other folding rules will be
tried.

These rules do not handle the case of an empty struct.  We add allow it
to be handled.

Fixes http://crbug/1030194

* Changes based on the review.
2019-12-10 14:58:30 -05:00
Sarah
0a5d99d02c Permit the debug instructions in WebGPU SPIR-V - remove from the optimizer (#3083)
continuing #3063
fixing #3052
2019-12-03 11:21:26 -05:00
David Neto
af7410597e graphics robust access: use signed clamp (#3073)
Access chain indices are always interpreted as signed integers.
So use signed clamp instead of unsigned clamp.  We must also
clamp to the max signed int for the index type.

Fixes #3072
2019-12-03 11:18:56 -05:00
Steven Perron
3ed4586044
Folding: perform add and sub on mismatched integer types (#3084)
Fixes #3040
2019-12-02 17:51:20 -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
Steven Perron
54385458ca
Handle unreachable block when computing register pressure (#3070)
Fixes #3053
2019-11-27 09:45:17 -05:00
David Neto
a62012cede
Add test with explicit example of stripping reflection info (#3064)
* Add test with explicit example of stripping reflection info

* Improve the comment on StripReflectEnd2EndExample
2019-11-26 16:20:45 -05:00
Steven Perron
0391d0823e
Handle OpPhi with no in operands in value numbering (#3056)
Fixes #3043
2019-11-19 09:45:39 -05:00
alan-baker
ab3cdcaef5 Fix operand access of composite in upgrade memory model (#3021)
Fixes #2992

* Accessing aggregate subtype used the wrong operand
* Added a test
2019-11-12 13:41:38 -05:00
alan-baker
1a18d491f2 Validate array stride does not cause overlap (#3028)
Fixes #3027

* Disallow array stride 0
* Check array stride against element size
* Fix up tests
* Add new tests
2019-11-12 13:36:53 -05:00
Ehsan
12e54dae16 Update Offset to ConstOffset bitmask if operand is constant. (#3024)
Update Offset to ConstOffset bitmask if operand is constant.

Fixes #3005
2019-11-11 22:35:14 -05:00