Commit Graph

1259 Commits

Author SHA1 Message Date
David Neto
1c0056c339 Start v2018.1-dev 2018-02-02 11:27:07 -05:00
David Neto
c430a41ae3 Finalize v2018.0 2018-02-02 11:25:58 -05:00
David Neto
bcd4f23930 Update CHANGES 2018-02-02 11:23:33 -05:00
Alan Baker
abe113219e Reordering performance passes ordering to produce better opts
* Moved initial insert/extract passes later to cover more opportunities
* Added an extra set of passes to clean up opportunities exposed later
in the pipeline
2018-02-01 18:01:10 -05:00
Victor Lomuller
50e85c865c Add LoopUtils class to gather some loop transformation support.
This patch adds LoopUtils class to handle some loop related transformations. For now it has 2 transformations that simplifies other transformations such as loop unroll or unswitch:
 - Dedicate exit blocks: this ensure that all exit basic block
   (out-of-loop basic blocks that have a predecessor in the loop)
   have all their predecessors in the loop;
 - Loop Closed SSA (LCSSA): this ensure that all definitions in a loop are used inside the loop
   or in a phi instruction in an exit basic block.

It also adds the following capabilities:
 - Loop::IsLCSSA to test if the loop is in a LCSSA form
 - Loop::GetOrCreatePreHeaderBlock that can build a loop preheader if required;
 - New methods to allow on the fly updates of the loop descriptors.
 - New methods to allow on the fly updates of the CFG analysis.
 - Instruction::SetOperand to allow expression of the index relative to Instruction::NumOperands (to be compatible with the index returned by DefUseManager::ForEachUse)
2018-02-01 15:35:09 -05:00
Steven Perron
61d8c0384b Add pass to reaplce invalid opcodes
Creates a pass that will remove instructions that are invalid for the
current shader stage.  For the instruction to be considered for replacement

1) The opcode must be valid for a shader modules.
2) The opcode must be invalid for the current shader stage.
3) All entry points to the module must be for the same shader stage.
4) The function containing the instruction must be reachable from an entry point.

Fixes #1247.
2018-02-01 15:25:09 -05:00
Andrey Tuganov
d37869c842 Added OpenCL ExtInst validation rules 2018-02-01 14:14:13 -05:00
Jeremy Hayes
cd68f2b176 Add adjacency validation pass
Validate OpPhi predecessors.
Validate OpLoopMerge successors.
Validate OpSelectionMerge successors.
Fix collateral damage to existing tests.
Remove ValidateIdWithMessage.OpSampledImageUsedInOpPhiBad.
2018-02-01 14:10:55 -05:00
Andrey Tuganov
905536c519 Fixed harmless uninit var warning 2018-01-31 17:49:01 -05:00
David Neto
ac537c71a8 Use SPIR-V headers from "unified1" directory 2018-01-31 15:36:50 -05:00
Alan Baker
2735e0851e Remove constexpr from Analysis operators
* Had to remove templating from InstructionBuilder as a result
 * now preserved analyses are specified as a constructor argument
* updated tests and uses
* changed static_assert to a runtime assert
 * this should probably get further changes in the future
2018-01-31 14:44:43 -05:00
GregF
0aa0ac52f7 Opt: Add ScalarReplacement to RegisterSizePasses 2018-01-31 10:19:17 -05:00
Andrey Tuganov
44d88c8d9c Add memory semantics checks to validate atomics 2018-01-30 18:00:01 -05:00
David Neto
38f297c194 Update CHANGES 2018-01-30 17:47:00 -05:00
Alan Baker
16949236fe Prevent unnecessary changes to the IR in dead branch elim
* When handling unreachable merges and continues, do not optimize to the
same IR
 * pass did not check whether the unreachable blocks were in the
 optimized form before transforming them
* added a test to catch this issue
2018-01-30 16:51:58 -05:00
Andrey Tuganov
c86cb76a22 Improved error message in val capabilities 2018-01-30 16:22:10 -05:00
Alan Baker
e661da7941 Enhancements to block merging
* Should handle all possibilities
 * Stricter checks for what is disallowed:
  * header and header
  * merge and merge
 * Allow header and merge blocks to be merged
  * Erases the structured control declaration if merging header and
    merge blocks together.
2018-01-30 16:05:51 -05:00
Alan Baker
6704233d39 Fix dereference of possibly nullptr
* If the dead branch elim is performed on a module without structured
control flow, the OpSelectionMerge may not be present
 * Add a check for pointer validity before dereferencing
* Added a test to catch the bug
2018-01-30 10:15:43 -05:00
GregF
f28b106173 InsertExtractElim: Split out DeadInsertElim as separate pass 2018-01-30 08:52:14 -05:00
Alan Baker
1b46f7ecad Fixes in CCP for #1228
* Forces traversal of phis if the def has changed to varying
* Mark a phi as varying if all incoming values are varying
* added a test to catch the bug
2018-01-29 15:12:05 -05:00
Victor Lomuller
6018de81de Add LoopDescriptor as an IRContext analysis.
Move some function definitions from header to source to avoid circular definition.
2018-01-25 16:12:32 -05:00
Greg Fischer
684997eb72 DeadInsertElim: Detect and DCE dead Inserts
This adds Dead Insert Elimination to the end of the
--eliminate-insert-extract pass. See the new tests for examples of code
that will benefit.

Essentially, this removes OpCompositeInsert instructions which are not
used, either because there is no instruction which uses the value at the
index it is inserted, or because a subsequent insert intercepts any such
use.

This code has been seen to remove significant amounts of dead code from
real-life HLSL shaders being ported to Vulkan. In fact, it is needed to
remove dead texture samples which cause Vulkan validation layer errors
(unbound textures and samplers) if not removed . Such DCE is thus
required for fxc equivalence and legalization.

This analysis operates across "chains" of Inserts which can also contain
Phi instructions.
2018-01-25 16:07:21 -05:00
Alan Baker
2e93e806e4 Initial implementation of if conversion
* Handles simple cases only
* Identifies phis in blocks with two predecessors and attempts to
convert the phi to an select
 * does not perform code motion currently so the converted values must
 dominate the join point (e.g. can't be defined in the branches)
 * limited for now to two predecessors, but can be extended to handle
 more cases
* Adding if conversion to -O and -Os
2018-01-25 09:42:00 -08:00
Andrey Tuganov
b2eb840468 Validator: restricted some atomic ops for shaders
Ban floating point case for OpAtomicLoad, OpAtomicExchange,
OpAtomicCompareExchange. In graphics (Shader) environments, these
instructions only operate on scalar integers. Ban the floating point
case. OpenCL supports atomic_float.
2018-01-24 14:06:06 -08:00
Andrey Tuganov
bdc78377bc Added Vulkan-specifc checks to image validation
Implemented Vulkan-specific rules:
- OpTypeImage must declare a scalar 32-bit float or 32-bit integer type
for the “Sampled Type”.
- OpSampledImage must only consume an “Image” operand whose type has its
“Sampled” operand set to 1.
2018-01-24 14:05:42 -08:00
Steven Perron
c4835e1bd8 Use id_map in Fold*ToConstant
The folding routines are suppose to use the id_map provided to map the
ids in the instruction.  The ones I just added are missing it.
2018-01-22 16:27:31 -05:00
Steven Perron
6c409e30a2 Add generic folding function and use in CCP
The current folding routines have a very cumbersome interface, make them
harder to use, and not a obvious how to extend.

This change is to create a new interface for the folding routines, and
show how it can be used by calling it from CCP.

This does not make a significant change to the behaviour of CCP.  In
general it should produce the same code as before; however it is
possible that an instruction that takes 32-bit integers as inputs and
the result is not a 32-bit integer or bool will not be folded as before.

It seems like andriod has a problem with INT32_MAX and the like.  I'll
explicitly define those if the are not already defined.
2018-01-22 14:26:49 -05:00
Alan Baker
3b780db7f8 Fixes infinite loop in ADCE
* Addresses how breaks are indentified to prevent infinite loops when
back to back loop share a merge and header
* Added test to catch the bug
2018-01-19 11:08:46 -05:00
Victor Lomuller
cf3b2a58c4 Introduce an instruction builder helper class.
The class factorize the instruction building process.
Def-use manager analysis can be updated on the fly to maintain coherency.
To be updated to take into account more analysis.
2018-01-19 10:17:45 -05:00
Alan Baker
73940aba1b Simplifying code for adding instructions to worklist
* AddToWorklist can now be called unconditionally
 * It will only add instructions that have not already been marked as
 live
 * Fixes a case where a merge was not added to the worklist because the
 branch was already marked as live
* Added two similar tests that fail without the fix
2018-01-18 20:36:46 -05:00
Steven Perron
34d4294c2c Create a pass to work around a driver bug related to OpUnreachable.
We have come across a driver bug where and OpUnreachable inside a loop
is causing the shader to go into an infinite loop.  This commit will try
to avoid this bug by turning OpUnreachable instructions that are
contained in a loop into branches to the loop merge block.

This is not added to "-O" and "-Os" because it should only be used if
the driver being targeted has this problem.

Fixes #1209.
2018-01-18 20:31:46 -05:00
Alan Baker
18618061cb Adding testcase for #1210 2018-01-18 12:58:07 -05:00
Victor Lomuller
0b1372a8ca CFG: force the creation of a predecessor entry for all basic block.
This ensure that all basic blocks in a function have a valid entry the CFG object.

The entry block has no predecessors but remains a valid basic block
for which we might want to query the number of predecessors.
Some unreachable basic blocks may not have predecessors as well.
2018-01-18 10:22:00 -05:00
David Neto
3604c0b71d spirv-dis: Add --color option to force color disassembly
Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/1170
2018-01-18 00:01:25 -05:00
Alan Baker
5e70d20d80 Fixing missing early exit from break identification 2018-01-17 14:09:24 -05:00
Alan Baker
80b743a570 Adding support for switch removal in ADCE
* Updated code to handle switches
* Enabled disabled test and added a couple new ones
2018-01-17 11:05:42 -05:00
Alan Baker
3a0eb44da3 Capturing value table by reference in local redundancy elim 2018-01-17 09:58:32 -05:00
David Neto
ae6daeed99 Update CHANGES 2018-01-16 22:52:39 -05:00
Alan Baker
5ffe862f28 Fixes missing increment in common uniform elim
* Addresses #1203
* Increments inIdx in IsConstantIndexAccessChain
 * added test to catch the bug
2018-01-16 14:47:35 -05:00
Steven Perron
6cc772c3ce Skip SpecConstants in CCP.
At the moment specialization constants look like constants to ccp.  This
causes a problem because they are handled differently by the constant
manager.

I choose to simply skip over them, and not try to add them to the value
table.  We can do specialization before ccp if we want to be able to
propagate these values.

Fixes #1199.
2018-01-15 09:53:23 -05:00
David Neto
ba017f79b2 Update CHANGES 2018-01-12 18:52:42 -05:00
Greg Fischer
c2aadb02d9 Add MatrixConstant 2018-01-12 18:49:36 -05:00
Steven Perron
8cb0aec724 Remove redundant passes from legalization passes
With work that Alan has done, some passes have become redundant.  ADCE
now removed unused variables.  Dead branch elimination removes
unreachable blocks.  This means we can remove CFG Cleanup and dead
variable elimination.
2018-01-12 17:47:50 -05:00
Alan Baker
6587d3f8a3 Adding early exit versions of several ForEach* methods
* Looked through code for instances where code would benefit from early
exit
 * Added a corresponding WhileEach* method and updated the code
2018-01-12 17:05:09 -05:00
Steven Perron
24f9947050 Move initialization of the const mgr to the constructor.
The current code expects the users of the constant manager to initialize
it with all of the constants in the module.  The problem is that you do
not want to redo the work multiple times.  So I decided to move that
code to the constructor of the constant manager.  This way it will
always be initialized on first use.

I also removed an assert that expects all constant instructions to be
successfully mapped.  This is because not all OpConstant* instruction
can map to a constant, and neither do the OpSpecConstant* instructions.

The real problem is that an OpConstantComposite can contain a member
that is OpUndef.  I tried to treat OpUndef like OpConstantNull, but this
failed because an OpSpecConstantComposite with an OpUndef cannot be
changed to an OpConstantComposite.  Since I feel this case will not be
common, I decided to not complicate the code.

Fixes #1193.
2018-01-12 13:53:21 -05:00
David Neto
86dec646f5 Start v2018.0-dev 2018-01-12 13:33:43 -05:00
David Neto
902ed46f6f Finalize v2017.3 2018-01-12 13:32:04 -05:00
Alan Baker
672494da13 Adding ostream operators for IR structures
* Added for Instruction, BasicBlock, Function and Module
* Uses new disassembly functionality that can disassemble individual
instructions
 * For debug use only (no caching is done)
 * Each output converts module to binary, parses and outputs an
 individual instruction
* Added a test for whole module output
* Disabling Microsoft checked iterator warnings
* Updated check_copyright.py to accept 2018
2018-01-12 11:19:58 -05:00
Alan Baker
eb0c73dad6 Maintain instruction to block mapping in phi insertion
* Changed MemPass::InsertPhiInstructions to set basic blocks for new
phis
* Local SSA elim now maintains instr to block mapping
 * Added a test and confirmed it fails without the updated phis
* IRContext::set_instr_block no longer builds the map if the analysis is
invalid
* Added instruction to block mapping verification to
IRContext::IsConsistent()
2018-01-12 10:16:53 -05:00
Greg Fischer
5eafc00ad5 InsertExtractElim: Optimize through VectorShuffle, Mix
This improves Extract replacement to continue through VectorShuffle.
It will also handle Mix with 0.0 or 1.0 in the a-value of the desired
component.

To facilitate optimization of VectorShuffle, the algorithm was refactored
to pass around the indices of the extract in a vector rather than pass the
extract instruction itself. This allows the indices to be modified as the
algorithm progresses.
2018-01-12 09:41:45 -05:00