Commit Graph

698 Commits

Author SHA1 Message Date
David Neto
0dbe184d32 Remove concept of FIRST_CONCRETE_* operand types 2017-12-18 09:48:51 -05:00
Alan Baker
616908503d Improving the usability of the type manager. The type manager hashes
types. This allows the lookup of type declaration ids from arbitrarily
constructed types. Users should be cautious when dealing with non-unique
types (structs and potentially pointers) to get the exact id if
necessary.

* Changed the spec composite constant folder to handle ambiguous composites
* Added functionality to create necessary instructions for a type
* Added ability to remove ids from the type manager
2017-12-18 08:20:56 -05:00
GregF
0f80406315 ADCE: Only mark true breaks and continues of live loops
This fixes issue #1075

- Mark continue when conditional branch with merge block.
  Only mark if merge block is not continue block.

- Handle conditional branch break with preceding merge
2017-12-15 11:53:57 -05:00
Jeremy Hayes
cdfbf26c13 Add primitive instruction validation pass 2017-12-15 09:53:29 -05:00
Andrey Tuganov
af7d5799a5 Refactor include of latest spir-v header versions 2017-12-14 11:18:20 -05:00
Andrey Tuganov
532b327d4d Add validation rules for atomic instructions
Validates all OpAtomicXXX instructions.
2017-12-13 18:29:38 -05:00
Diego Novillo
853a3d6c31 Fix uninitialized warning at -Os. 2017-12-12 15:46:09 -05:00
Greg Fischer
22faa2b083 ADCE: Empty Loop Elimination
This entirely eliminates loops which do not contain live code.
2017-12-12 13:53:15 -05:00
Steven Perron
07ce16d1e7 Set the parent for basic blocks during inlining.
Inlining is not setting the parent (function) for each basic block.
This can cause problems for later optimizations.  The solution is to set
the parent for each new block just before it is linked into the
function.
2017-12-12 13:39:08 -05:00
Andrey Tuganov
c520d43649 Add validator checks for sparse image opcodes 2017-12-12 12:04:23 -05:00
Pierre Moreau
12447d8465 Support OpenCL 1.2 and 2.0 target environments
include: Add target environment enums for OpenCL 1.2 and 2.0

Validator: Validate OpenCL capabilities

Update validate capabilities to handle embedded profiles

Add test for OpenCL capabilities validation

Update messages to mention the OpenCL profile used

Re-format val_capability_test.cpp
2017-12-12 11:35:39 -05:00
Andrey Tuganov
dbd8d0e7b8 Reenable OpCopyObject validation rules
Vulkan CTS fix has been submitted.
2017-12-11 12:33:11 -05:00
Alan Baker
867451f49e Add scalar replacement
Adds a scalar replacement pass. The pass considers all function scope
variables of composite type. If there are accesses to individual
elements (and it is legal) the pass replaces the variable with a
variable for each composite element and updates all the uses.

Added the pass to -O
Added NumUses and NumUsers to DefUseManager
Added some helper methods for the inst to block mapping in context
Added some helper methods for specific constant types

No longer generate duplicate pointer types.

* Now searches for an existing pointer of the appropriate type instead
of failing validation
* Fixed spec constant extracts
* Addressed changes for review
* Changed RunSinglePassAndMatch to be able to run validation
 * current users do not enable it

Added handling of acceptable decorations.

* Decorations are also transfered where appropriate

Refactored extension checking into FeatureManager

* Context now owns a feature manager
 * consciously NOT an analysis
 * added some test
* fixed some minor issues related to decorates
* added some decorate related tests for scalar replacement
2017-12-11 10:51:13 -05:00
GregF
78c025abe9 MultiStore: Support OpVariable Initialization
Treat an OpVariable with initialization as if it was an OpStore.
With PR #1073, this completes work for issue #1017.
2017-12-11 10:37:14 -05:00
GregF
c6fdf68c2f SingleStore: Support OpVariable Initialization
Treat an OpVariable with initialization as if it was an OpStore.
This fixes issue #1017.
2017-12-08 16:02:14 -05:00
Diego Novillo
241dcacc04 Add a new constant manager class.
This patch adds a new constant manager class to interface with
analysis::Constant.  The new constant manager lives in ir::IRContext
together with the type manager (analysis::TypeManager).

The new analysis::ConstantManager is used by the spec constant folder
and the constant propagator (in progress).

Another cleanup introduced by this patch removes the ID management from
the fold spec constant pass, and ir::IRContext and moves it to
ir::Module. SSA IDs were maintained by IRContext and Module.  That's
pointless and leads to mismatch IDs. Fixed by moving all the bookkeeping
to ir::Module.
2017-12-08 14:14:55 -05:00
Steven Perron
5d602abd66 Add global redundancy elimination
Adds a pass that looks for redundant instruction in a function, and
removes them.  The algorithm is a hash table based value numbering
algorithm that traverses the dominator tree.

This pass removes completely redundant instructions, not partially
redundant ones.
2017-12-07 18:35:38 -05:00
Steven Perron
851e1ad985 Kill names and decoration in inlining.
Currently when inlining a call, the name and decorations for the result of the
call is not deleted.  This should be changed.  Added a test for this as well.

This fixes issue #622.
2017-12-07 12:20:45 -05:00
Victor Lomuller
731d1899b1 Add depth first iterator for trees
- Add generic depth first iterator
 - Update the dominator tree to use this iterator instead of "randomly"
   iterate over the nodes
2017-12-07 10:07:56 -05:00
Diego Novillo
0c2396d20f Revert extraneous changes from commit 8ec62deb2.
Commit 8ec62deb2 merged the code from PR #810, but it also re-introduces
code that had been removed in #885.

This patch removes the (now superfluous code).
2017-12-06 16:04:47 -05:00
Stephen McGroarty
8ba68fa9b9 Dominator Tree Analysis (#3)
Support for dominator and post dominator analysis on ir::Functions. This patch contains a DominatorTree class for building the tree and DominatorAnalysis and DominatorAnalysisPass classes for interfacing and caching the built trees.
2017-12-05 22:59:43 -05:00
Andrey Tuganov
94e3e7b8ef Add composite instruction validation pass
Validates instructions in the opcode range from OpVectorExtractDynamic
to OpTranspose.
2017-12-05 10:15:51 -05:00
Andrey Tuganov
bf184310b2 Fix some of the known issues in image validation
Applied some of the spec clarifications made in conversation with
@johnkslang.
2017-12-04 18:57:34 -05:00
Steven Perron
fd3a22042b DCEInst kill the same instruction twice.
In DCEInst, it is possible that the same instruction ends up in the
queue multiple times, if the same id is used multiple times in the
same instruction.

The solution is to keep the ids in a set, to ensure no duplication in
the list.
2017-12-04 18:15:35 -05:00
Diego Novillo
e9ecc0cbfd Remove cfg_ field from SSAPropagator class - NFC.
When I moved the CFG into IRContext
(https://github.com/KhronosGroup/SPIRV-Tools/pull/1019), I forgot to
update SSAPropagator to stop requiring one.

Fixed with this patch.
2017-12-04 15:28:21 -05:00
Steven Perron
65046eca7c Change IRContext::KillInst to delete instructions.
The current method of removing an instruction is to call ToNop.  The
problem with this is that it leaves around an instruction that later
passes will look at.  We should just delete the instruction.

In MemPass there is a utility routine called DCEInst.  It can delete
essentially any instruction, which can invalidate pointers now that they
are actually deleted.  The interface was changed to add a call back that
can be used to update any local data structures that contain
ir::Intruction*.
2017-12-04 11:07:45 -05:00
Steven Perron
b35b52f97b Compute value number when the value table is constructed.
Computing the value numbers on demand, as we do now, can lead to
different results depending on the order in which the users asks for
the value numbers.  To make things more stable, we compute them ahead
of time.
2017-12-04 11:02:04 -05:00
Daan Wendelen
b98254b282 Fixed typo that leaked to the binary
The typo was found by lintian when I was packaging glslang
2017-12-03 20:42:14 -05:00
Lei Zhang
0dd4ee27b1 Fix Dref type check in validator
Dref should be of 32-bit scalar floating type.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/1012
2017-12-01 10:17:45 -05:00
Pierre Moreau
69043963e4 Opt: Remove unused lambda captures
Those are reported as errors by clang 5.0.0, due to the flags -Werror
and -Wunused-lambda-capture.
2017-12-01 09:54:37 -05:00
Lei Zhang
137953538a Support outputting ANSI color escape sequences in library
Previously we required _PRINT to enable _COLOR, which forbids
outputting colored disassembly into a string in library.

This commit will allow library users to request enabling
ANSI color escape sequences.
2017-12-01 09:03:35 -05:00
David Neto
188cd3780d Erase decorations removed from internal collections
Fixes Android arm-64-v8a build with NDK r14.  That's because
we no longer ignore the result of the std::remove.
2017-11-30 11:35:02 -05:00
David Neto
3c2e4c7d99 Fix validation of group ops in SPV_AMD_shader_ballot
This needs custom code since the rules from the extension
are not encoded in the grammar.

Changes are:
- The new group instructions don't require Group capability
  when the extension is declared.
- The Reduce, InclusiveScan, ExclusiveScan normally require the Kernel
  capability, but don't when the extension is declared.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/991
2017-11-30 10:26:04 -05:00
Diego Novillo
8cfa0c40e0 Fix #1034 - Give Edge::operator<() weak ordering semantics.
This should fix #1034.  It changes the predicate on operator< to use
label IDs from each block and compares them as std:pair to define a weak
ordering for std::set.
2017-11-29 17:29:17 -05:00
Andrey Tuganov
e1ceff9f54 Validate OpTypeImage and OpTypeSampleImage
Added new validation rules to the validate image pass.
2017-11-29 13:21:04 -05:00
GregF
8dd3d93cf6 AggressiveDCE: Add merge and continue branches for live loop.
This ensures that an if-break is not eliminated from a loop.

This fixes issue #989
2017-11-29 09:56:21 -05:00
Diego Novillo
9f20799fb4 Convert the CFG to an on-demand analysis - NFC.
This fixes some TODOs by moving the CFG into the IRContext as an
analysis.
2017-11-28 13:25:41 -05:00
Diego Novillo
74327845aa Generic value propagation engine.
This class implements a generic value propagation algorithm based on the
conditional constant propagation algorithm proposed in

     Constant propagation with conditional branches,
     Wegman and Zadeck, ACM TOPLAS 13(2):181-210.

The implementation is based on

     A Propagation Engine for GCC
     Diego Novillo, GCC Summit 2005
     http://ols.fedoraproject.org/GCC/Reprints-2005/novillo-Reprint.pdf

The purpose of this implementation is to act as a common framework for any
transformation that needs to propagate values from statements producing new
values to statements using those values.
2017-11-27 23:32:06 -05:00
Diego Novillo
491b112fd2 Fix windows build.
This fixes the lack of uint32_t definition in source/val/decoration.h.
2017-11-27 14:40:03 -05:00
Diego Novillo
83228137e1 Re-format source tree - NFC.
Re-formatted the source tree with the command:

$ /usr/bin/clang-format -style=file -i \
    $(find include source tools test utils -name '*.cpp' -or -name '*.h')

This required a fix to source/val/decoration.h.  It was not including
spirv.h, which broke builds when the #include headers were re-ordered by
clang-format.
2017-11-27 14:31:49 -05:00
Andrey Tuganov
d8b2013ecf Derivative opcodes require Fragment exec model
Added validator check that all derivative opcodes require Fragment
execution model.
2017-11-27 12:05:25 -05:00
Andrey Tuganov
c170afd93b Relaxed OpImageWrite texel type check 2017-11-24 14:31:08 -05:00
Andrey Tuganov
f84f266977 Relaxed OpImageRead validation rules
Removed the check that result type of OpImageRead should be a vector4.
Will reenable/adapt once the spec is clarified on what the right
dimension should be.
2017-11-24 10:12:24 -05:00
Alan Baker
0cae89e79e Notify the context of instructions that are being erased.
Fixes use-after-free error in RemoveDuplicatesPass

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/1004
2017-11-23 23:43:25 -05:00
Andrey Tuganov
3e08a3f718 Add validation checks for Execution Model
Currently checks that these instructions are called from entry points
with Fragment execution model.
OpImageImplicit*
OpImageQueryLod
OpKill
2017-11-23 23:38:03 -05:00
David Neto
d9129f00a5 Test for pollution of the global namespace
Works on Linux only for now.  That's a good start.

Move ValidateBinaryUsingContextAndValidationState into anonymous
namespace in source/validate.cpp.
2017-11-23 21:27:21 -05:00
Steven Perron
0b1cb27f83 Remove derivative instructions from the list of combinators.
These instructions compute their value based the value of the immediate
neighbours of the current fragment.  This means the result is not
defined purely by the operands of the instruction.
2017-11-23 18:37:43 -05:00
Lei Zhang
aec60b8158 Add RegisterLegalizationPasses() into the interface
Add note to mention the use scenario.  The original list came
from Glslang.
2017-11-23 17:26:44 -05:00
Alan Baker
746bfd210a Adding new def -> use mapping container
Replaced representation of uses

* Changed uses from unordered_map<uint32_t, UseList> to
set<pairInstruction*, Instruction*>>
* Replaced GetUses with ForEachUser and ForEachUse functions
* updated passes to use new functions
* partially updated tests
* lots of cleanup still todo

Adding an unique id to Instruction generated by IRContext

Each instruction is given an unique id that can be used for ordering
purposes. The ids are generated via the IRContext.

Major changes:
* Instructions now contain a uint32_t for unique id and a cached context
pointer
 * Most constructors have been modified to take a context as input
 * unfortunately I cannot remove the default and copy constructors, but
 developers should avoid these
* Added accessors to parents of basic block and function
* Removed the copy constructors for BasicBlock and Function and replaced
them with Clone functions
* Reworked BuildModule to return an IRContext owning the built module
 * Since all instructions require a context, the context now becomes the
basic unit for IR
* Added a constructor to context to create an owned module internally
* Replaced uses of Instruction's copy constructor with Clone whereever I
found them
* Reworked the linker functionality to perform clones into a different
context instead of moves
* Updated many tests to be consistent with the above changes
 * Still need to add new tests to cover added functionality
* Added comparison operators to Instruction

Adding tests for Instruction, IRContext and IR loading

Fixed some header comments for BuildModule

Fixes to get tests passing again

* Reordered two linker steps to avoid use/def problems
* Fixed def/use manager uses in merge return pass
* Added early return for GetAnnotations
* Changed uses of Instruction::ToNop in passes to IRContext::KillInst

Simplifying the uses for some contexts in passes
2017-11-23 16:40:02 -05:00
Lei Zhang
b02c9a5802 Allow derived access chain without uses in access chain conversion 2017-11-23 16:00:28 -05:00