Commit Graph

770 Commits

Author SHA1 Message Date
Jaebaek Seo
b78f4b1518
Remove DebugDeclare only for target variables in ssa-rewrite (#3511)
For each local variable, ssa-rewrite should remove its DebugDeclare
if and only if it is replaced by any number of DebugValues for store
and phi instructions.

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

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

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

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

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

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

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

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

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

   int foo_a; // after scalar replacement
   int foo_b;

   DebugDeclare %dbg_foo %foo %null_expr // before

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

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

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

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

* Fix typo in comments.

* Load replacement var before use; and added test.

* fix formatting

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

Fixes #3343 

When CCP is evaluating an instruction, it was trying to fold a
comparison with 64 bit integers.  This was causing a fold failure later
since the folder still cannot deal with 64 bit integers.
2020-05-21 12:58:08 -04:00
Steven Perron
3c47dac282
Add unrolling to performance passes (#3082)
Unroll loops that are marked as unroll when doing -O.  Add cleanup
optimizations after unrolling.

Fixes #3067
2020-05-20 15:43:13 -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
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
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
Steven Perron
49ca250b44
Delete nullptr in function bb list immedietly (#3326)
When moving blocks around, we ended up with a nullptr for a basic block,
and it was left in the list for a little bit.  However, in that time, it
would end up being dereferenced while traversing the function.

To fix this, we delete it right away.  This was found in an asan build
that runs our current tests.  No new tests are needed, but I did add
extra check asan checks for our asan bot.
2020-04-28 21:54:08 -04: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
61b7de3c39
Remove unreachable code. (#3304) 2020-04-15 14:41:52 -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
4956644894
Add tests for recently added command line option (#3297)
We have not added tests for the new command line options recently.  I've
updated the test and fixed on option that was incorrect.

Fixes #3247
2020-04-14 12:57:06 -04:00