Commit Graph

779 Commits

Author SHA1 Message Date
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
alan-baker
b4c4da3e76
Improve non-semantic instruction handling in the optimizer (#3693)
* No longer blindly add global non-semantic info instructions to global
  types and values
  * functions now have a list of non-semantic instructions that succeed
    them in the global scope
  * global non-semantic instructions go in global types and values if
    they appear before any function, otherwise they are attached to the
    immediate function predecessor in the module
* changed ADCE to use the function removal utility
* Modified EliminateFunction to have special handling for non-semantic
  instructions in the global scope
  * non-semantic instructions are moved to an earlier function (or full
    global set) if the function they are attached to is eliminated
  * Added IRContext::KillNonSemanticInfo to remove the tree of
    non-semantic instructions that use an instruction
  * this is used in function elimination
* There is still significant work in the optimizer to handle
  non-semantic instructions fully in the optimizer
2020-08-13 14:54:14 -04:00
Vasyl Teliman
948577c5df
Fix the bug (#3680) 2020-08-13 09:09:57 -04:00
Vasyl Teliman
1435e427da
Fix the bug (#3683) 2020-08-12 13:00:41 -04:00
Jaebaek Seo
f0ca96d12c
Preserve debug info in dead-insert-elim pass (#3652)
When we determine the liveness of an insert, we have to ignore the debug
instruction (it must not have any impact on the decision).
2020-08-12 10:19:37 -04:00
Steven Perron
8e1380996d
Handle no index access chain in local access chain convert (#3678)
* Handle no index access chain in local access chain convert

Fixes #3643
2020-08-10 22:03:02 -04:00
Steven Perron
2990a21926
Avoid using /MP4 for clang on windows. (#3662) 2020-08-10 10:59:24 -04:00
André Perez
3f33a9aa55
spirv-opt: Improve the code of the Instruction class (#3610) 2020-08-05 15:28:05 -04:00
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