platform/upstream/SPIRV-Tools.git
6 years agoFix comment in primitives validation
Jeremy Hayes [Mon, 18 Dec 2017 17:44:18 +0000 (10:44 -0700)]
Fix comment in primitives validation

Also refactor type query for efficiency.

6 years agoImage Operand Sample allows sparse image opcodes
Andrey Tuganov [Mon, 18 Dec 2017 16:21:38 +0000 (11:21 -0500)]
Image Operand Sample allows sparse image opcodes

@ehsannas had filed an issue against SPIR-V spec, concerning
Image Operands section (3.14):
Sample
A following operand is the sample number of the sample to use. Only
valid with OpImageFetch, OpImageRead, and OpImageWrite.

Relaxing the check to allow OpImageSparseRead and
OpImageSparseFetch to fix failing tests.

6 years agoExport a config file for pkg-config
Pierre Moreau [Sat, 25 Nov 2017 17:58:50 +0000 (18:58 +0100)]
Export a config file for pkg-config

Fixes #1031

Extracts the current version from the file CHANGES

The -dev suffix maps to a minor version number of .0
No -dev suffix maps to a minor version number of .1

Uses a first class target spirv-tools-pkg-config

6 years agoRemove concept of FIRST_CONCRETE_* operand types
David Neto [Sun, 3 Dec 2017 19:26:16 +0000 (14:26 -0500)]
Remove concept of FIRST_CONCRETE_* operand types

6 years agoImproving the usability of the type manager. The type manager hashes
Alan Baker [Fri, 8 Dec 2017 20:33:19 +0000 (15:33 -0500)]
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

6 years agoStart v2017.3-dev
David Neto [Fri, 15 Dec 2017 23:24:41 +0000 (18:24 -0500)]
Start v2017.3-dev

6 years agoFinalize v2017.2
David Neto [Fri, 15 Dec 2017 23:21:55 +0000 (18:21 -0500)]
Finalize v2017.2

6 years agoADCE: Only mark true breaks and continues of live loops
GregF [Tue, 12 Dec 2017 21:27:46 +0000 (14:27 -0700)]
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

6 years agoAdd primitive instruction validation pass
Jeremy Hayes [Thu, 14 Dec 2017 22:29:37 +0000 (15:29 -0700)]
Add primitive instruction validation pass

6 years agoRefactor include of latest spir-v header versions
Andrey Tuganov [Wed, 13 Dec 2017 22:55:00 +0000 (17:55 -0500)]
Refactor include of latest spir-v header versions

6 years agoAdd validation rules for atomic instructions
Andrey Tuganov [Thu, 30 Nov 2017 16:29:05 +0000 (11:29 -0500)]
Add validation rules for atomic instructions

Validates all OpAtomicXXX instructions.

6 years agoFix uninitialized warning at -Os.
Diego Novillo [Tue, 12 Dec 2017 20:46:09 +0000 (15:46 -0500)]
Fix uninitialized warning at -Os.

6 years agoADCE: Empty Loop Elimination
Greg Fischer [Wed, 25 Oct 2017 00:58:48 +0000 (18:58 -0600)]
ADCE: Empty Loop Elimination

This entirely eliminates loops which do not contain live code.

6 years agoSet the parent for basic blocks during inlining.
Steven Perron [Mon, 11 Dec 2017 18:10:24 +0000 (13:10 -0500)]
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.

6 years agoAppveyor: stop testing on VS 2013
Lei Zhang [Tue, 12 Dec 2017 15:46:39 +0000 (10:46 -0500)]
Appveyor: stop testing on VS 2013

re2 requires VS2015 or later since:

https://github.com/google/re2/commit/97957299d1c9f7617cfe653f344536d733582d9e

6 years agoAdd validator checks for sparse image opcodes
Andrey Tuganov [Fri, 8 Dec 2017 22:57:12 +0000 (17:57 -0500)]
Add validator checks for sparse image opcodes

6 years agoSupport OpenCL 1.2 and 2.0 target environments
Pierre Moreau [Wed, 29 Nov 2017 23:49:23 +0000 (00:49 +0100)]
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

6 years agoAppVeyor: Put VS 2017 first
David Neto [Mon, 11 Dec 2017 20:50:51 +0000 (15:50 -0500)]
AppVeyor: Put VS 2017 first

VS 2017 is the newest compiler, with the most interesting feedback.
Place it first so we get its feedback first.

6 years agoForce gtest to expose ::testing::Combine
David Neto [Mon, 11 Dec 2017 17:05:04 +0000 (12:05 -0500)]
Force gtest to expose ::testing::Combine

Work around faulty logic in googletest, where ::testing::Combine
is accidentally disabled for VS 2017.
See https://github.com/google/googletest/issues/1352

6 years agoReenable OpCopyObject validation rules
Andrey Tuganov [Mon, 11 Dec 2017 17:33:11 +0000 (12:33 -0500)]
Reenable OpCopyObject validation rules

Vulkan CTS fix has been submitted.

6 years agoAdd scalar replacement
Alan Baker [Thu, 30 Nov 2017 22:03:06 +0000 (17:03 -0500)]
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

6 years agoMultiStore: Support OpVariable Initialization
GregF [Fri, 8 Dec 2017 17:44:15 +0000 (10:44 -0700)]
MultiStore: Support OpVariable Initialization

Treat an OpVariable with initialization as if it was an OpStore.
With PR #1073, this completes work for issue #1017.

6 years agoAdd external/SPIRV-Headers to .gitignore
Pierre Moreau [Sat, 9 Dec 2017 20:50:38 +0000 (21:50 +0100)]
Add external/SPIRV-Headers to .gitignore

b93c066b allowed for both SPIRV-Headers and spirv-headers as valid
paths, but only the latter is being ignored by Git.

6 years agoSingleStore: Support OpVariable Initialization
GregF [Thu, 7 Dec 2017 19:11:29 +0000 (12:11 -0700)]
SingleStore: Support OpVariable Initialization

Treat an OpVariable with initialization as if it was an OpStore.
This fixes issue #1017.

6 years agoAdd option to spirv-opt to skip the validator.
Steven Perron [Thu, 7 Dec 2017 15:55:57 +0000 (10:55 -0500)]
Add option to spirv-opt to skip the validator.

The option --skip-validation is added.  When used it will skip the
validation step.

Also rearranged the help text to fix two options that are out of order.

6 years agoAdd a new constant manager class.
Diego Novillo [Thu, 7 Dec 2017 21:42:27 +0000 (16:42 -0500)]
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.

6 years agoAdd global redundancy elimination
Steven Perron [Mon, 4 Dec 2017 17:29:51 +0000 (12:29 -0500)]
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.

6 years agoKill names and decoration in inlining.
Steven Perron [Thu, 7 Dec 2017 03:09:20 +0000 (22:09 -0500)]
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.

6 years agoAdd depth first iterator for trees
Victor Lomuller [Mon, 4 Dec 2017 14:36:05 +0000 (14:36 +0000)]
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

6 years agoRevert extraneous changes from commit 8ec62deb2.
Diego Novillo [Wed, 6 Dec 2017 19:56:56 +0000 (14:56 -0500)]
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).

6 years agoDominator Tree Analysis (#3)
Stephen McGroarty [Mon, 27 Nov 2017 21:21:26 +0000 (21:21 +0000)]
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.

6 years agoSort flags in help message - NFC.
Diego Novillo [Tue, 5 Dec 2017 16:28:12 +0000 (11:28 -0500)]
Sort flags in help message - NFC.

It's slightly easier to read flags from --help if they're sorted.

6 years agoCMake: allow both SPIRV-Headers and spirv-headers
Lei Zhang [Tue, 5 Dec 2017 15:55:00 +0000 (10:55 -0500)]
CMake: allow both SPIRV-Headers and spirv-headers

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/1057

6 years agoAdd composite instruction validation pass
Andrey Tuganov [Tue, 5 Dec 2017 15:15:51 +0000 (10:15 -0500)]
Add composite instruction validation pass

Validates instructions in the opcode range from OpVectorExtractDynamic
to OpTranspose.

6 years agoDo not zip and deploy for check formatting
Lei Zhang [Tue, 5 Dec 2017 03:43:26 +0000 (22:43 -0500)]
Do not zip and deploy for check formatting

6 years agoGo back to root directory
Lei Zhang [Tue, 5 Dec 2017 00:39:00 +0000 (19:39 -0500)]
Go back to root directory

6 years agoTravis CI: add clang-format check
Lei Zhang [Fri, 1 Dec 2017 03:24:13 +0000 (22:24 -0500)]
Travis CI: add clang-format check

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/1029

6 years agoUpdate .appveyor.yml
Diego Novillo [Mon, 4 Dec 2017 20:41:41 +0000 (15:41 -0500)]
Update .appveyor.yml

6 years agoFix some of the known issues in image validation
Andrey Tuganov [Mon, 4 Dec 2017 17:50:47 +0000 (12:50 -0500)]
Fix some of the known issues in image validation

Applied some of the spec clarifications made in conversation with
@johnkslang.

6 years agoDCEInst kill the same instruction twice.
Steven Perron [Mon, 4 Dec 2017 17:29:51 +0000 (12:29 -0500)]
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.

6 years agoChange Release builds to Release with debug info on Linux
Diego Novillo [Mon, 4 Dec 2017 20:45:56 +0000 (15:45 -0500)]
Change Release builds to Release with debug info on Linux

For Linux builds, we want to add debug information on the generated binary (for timing and profiling purposes).  This patch changes Release builds to RelWithDebInfo.

6 years agoRemove cfg_ field from SSAPropagator class - NFC.
Diego Novillo [Mon, 4 Dec 2017 20:28:21 +0000 (15:28 -0500)]
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.

6 years agoChange IRContext::KillInst to delete instructions.
Steven Perron [Tue, 21 Nov 2017 19:47:46 +0000 (14:47 -0500)]
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*.

6 years agoCompute value number when the value table is constructed.
Steven Perron [Mon, 27 Nov 2017 20:07:34 +0000 (15:07 -0500)]
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.

6 years agoFixed typo that leaked to the binary
Daan Wendelen [Sun, 3 Dec 2017 20:27:21 +0000 (21:27 +0100)]
Fixed typo that leaked to the binary

The typo was found by lintian when I was packaging glslang

6 years agoAdd simplified instructions for pushing a reviewed PR.
Diego Novillo [Fri, 1 Dec 2017 18:10:34 +0000 (13:10 -0500)]
Add simplified instructions for pushing a reviewed PR.

6 years agoTravis: mark MacOS builds as optional
Lei Zhang [Fri, 1 Dec 2017 04:06:55 +0000 (23:06 -0500)]
Travis: mark MacOS builds as optional

MacOS support in Travis is flakey right now. MacOS build jobs
take a long time to start.

We have extensive checks for Linux and Windows, which should give
us confidence.

6 years agoRe-format CONTRIBUTING.md - NFC.
Diego Novillo [Fri, 1 Dec 2017 17:17:47 +0000 (12:17 -0500)]
Re-format CONTRIBUTING.md - NFC.

I'm about to change this file.  I re-formatted it for easier editing.

6 years agoFix Dref type check in validator
Lei Zhang [Thu, 30 Nov 2017 23:01:11 +0000 (18:01 -0500)]
Fix Dref type check in validator

Dref should be of 32-bit scalar floating type.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/1012

6 years agoAppveyor: use ninja instead of MSBuild
Lei Zhang [Fri, 1 Dec 2017 02:12:23 +0000 (21:12 -0500)]
Appveyor: use ninja instead of MSBuild

6 years agoOpt: Remove unused lambda captures
Pierre Moreau [Thu, 30 Nov 2017 21:32:44 +0000 (22:32 +0100)]
Opt: Remove unused lambda captures

Those are reported as errors by clang 5.0.0, due to the flags -Werror
and -Wunused-lambda-capture.

6 years agoSupport outputting ANSI color escape sequences in library
Lei Zhang [Thu, 30 Nov 2017 21:35:22 +0000 (16:35 -0500)]
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.

6 years agoErase decorations removed from internal collections
David Neto [Wed, 29 Nov 2017 20:58:35 +0000 (15:58 -0500)]
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.

6 years agoFix validation of group ops in SPV_AMD_shader_ballot
David Neto [Fri, 24 Nov 2017 19:18:17 +0000 (14:18 -0500)]
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

6 years agoFix #1034 - Give Edge::operator<() weak ordering semantics.
Diego Novillo [Wed, 29 Nov 2017 18:36:17 +0000 (13:36 -0500)]
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.

6 years agoValidate OpTypeImage and OpTypeSampleImage
Andrey Tuganov [Wed, 22 Nov 2017 21:57:37 +0000 (16:57 -0500)]
Validate OpTypeImage and OpTypeSampleImage

Added new validation rules to the validate image pass.

6 years agoLinker: Fix incorrect exit status.
Daniel Schürmann [Wed, 29 Nov 2017 13:38:27 +0000 (14:38 +0100)]
Linker: Fix incorrect exit status.

6 years agoCreate CONTRIBUTING.md
Steven Perron [Fri, 24 Nov 2017 14:33:18 +0000 (09:33 -0500)]
Create CONTRIBUTING.md

This is intended to be a document that people who want to help the project
can get a quick overview of how things are done.  Please comment and suggest
any changes.

6 years agoAggressiveDCE: Add merge and continue branches for live loop.
GregF [Tue, 28 Nov 2017 23:18:05 +0000 (16:18 -0700)]
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

6 years agoUpdate README about the automatic master-tot relase
Lei Zhang [Mon, 27 Nov 2017 22:51:18 +0000 (17:51 -0500)]
Update README about the automatic master-tot relase

6 years agoConvert the CFG to an on-demand analysis - NFC.
Diego Novillo [Mon, 27 Nov 2017 19:20:32 +0000 (14:20 -0500)]
Convert the CFG to an on-demand analysis - NFC.

This fixes some TODOs by moving the CFG into the IRContext as an
analysis.

6 years agoFix windows build. unsigned vs signed comparison in EXPECT_EQ.
Diego Novillo [Tue, 28 Nov 2017 13:27:10 +0000 (08:27 -0500)]
Fix windows build. unsigned vs signed comparison in EXPECT_EQ.

6 years agoGeneric value propagation engine.
Diego Novillo [Fri, 17 Nov 2017 13:59:25 +0000 (08:59 -0500)]
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.

6 years agoFix windows build.
Diego Novillo [Mon, 27 Nov 2017 19:40:03 +0000 (14:40 -0500)]
Fix windows build.

This fixes the lack of uint32_t definition in source/val/decoration.h.

6 years agoRe-format source tree - NFC.
Diego Novillo [Mon, 27 Nov 2017 15:16:41 +0000 (10:16 -0500)]
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.

6 years agoDerivative opcodes require Fragment exec model
Andrey Tuganov [Fri, 24 Nov 2017 15:29:05 +0000 (10:29 -0500)]
Derivative opcodes require Fragment exec model

Added validator check that all derivative opcodes require Fragment
execution model.

6 years agoRelaxed OpImageWrite texel type check
Andrey Tuganov [Fri, 24 Nov 2017 15:55:05 +0000 (10:55 -0500)]
Relaxed OpImageWrite texel type check

6 years agoUpdate CHANGES to mention fixes for 1007 and 1009
David Neto [Fri, 24 Nov 2017 15:17:13 +0000 (10:17 -0500)]
Update CHANGES to mention fixes for 1007 and 1009

6 years agoRelaxed OpImageRead validation rules
Andrey Tuganov [Fri, 24 Nov 2017 15:05:07 +0000 (10:05 -0500)]
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.

6 years agoNotify the context of instructions that are being erased.
Alan Baker [Fri, 24 Nov 2017 04:08:58 +0000 (23:08 -0500)]
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

6 years agoAdd validation checks for Execution Model
Andrey Tuganov [Thu, 23 Nov 2017 17:11:15 +0000 (12:11 -0500)]
Add validation checks for Execution Model

Currently checks that these instructions are called from entry points
with Fragment execution model.
OpImageImplicit*
OpImageQueryLod
OpKill

6 years agoTest for pollution of the global namespace
David Neto [Wed, 22 Nov 2017 22:03:55 +0000 (17:03 -0500)]
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.

6 years agoRemove derivative instructions from the list of combinators.
Steven Perron [Thu, 23 Nov 2017 17:41:10 +0000 (12:41 -0500)]
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.

6 years agoStart v2017.2-dev
David Neto [Thu, 23 Nov 2017 23:16:41 +0000 (18:16 -0500)]
Start v2017.2-dev

6 years agoFinalize 2017.1
David Neto [Thu, 23 Nov 2017 23:12:23 +0000 (18:12 -0500)]
Finalize 2017.1

Updated CHANGES to cover main updates since 2017.0

6 years agoAdd RegisterLegalizationPasses() into the interface
Lei Zhang [Fri, 17 Nov 2017 21:50:43 +0000 (16:50 -0500)]
Add RegisterLegalizationPasses() into the interface

Add note to mention the use scenario.  The original list came
from Glslang.

6 years agoAdding new def -> use mapping container
Alan Baker [Tue, 14 Nov 2017 19:11:50 +0000 (14:11 -0500)]
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

6 years agoAllow derived access chain without uses in access chain conversion
Lei Zhang [Thu, 23 Nov 2017 20:16:48 +0000 (15:16 -0500)]
Allow derived access chain without uses in access chain conversion

6 years agoAdd derivatives validation pass
Andrey Tuganov [Wed, 22 Nov 2017 17:07:23 +0000 (12:07 -0500)]
Add derivatives validation pass

Checks operands of instructions in opcode range from OpDPdx to
OpFwidthCoarse.

6 years agoMove SetContextMessageConsumer into libspirv namespace
David Neto [Wed, 22 Nov 2017 20:18:37 +0000 (15:18 -0500)]
Move SetContextMessageConsumer into libspirv namespace

Avoid polluting the global namespace.

6 years agoCreate a local value numbering pass
Steven Perron [Sat, 11 Nov 2017 01:26:55 +0000 (20:26 -0500)]
Create a local value numbering pass

Creates a pass that removes redundant instructions within the same basic
block.  This will be implemented using a hash based value numbering
algorithm.

Added a number of functions that check for the Vulkan descriptor types.
These are used to determine if we are variables are read-only or not.

Implemented a function to check if loads and variables are read-only.
Implemented kernel specific and shader specific versions.

A big change is that the Combinator analysis in ADCE is factored out
into the IRContext as an analysis. This was done because it is being
reused in the value number table.

6 years agoValidator pass for image instructions
Andrey Tuganov [Thu, 26 Oct 2017 19:30:23 +0000 (15:30 -0400)]
Validator pass for image instructions

Includes validation rules for OpImageXXX and ImageOperand.

Doesn't include OpTypeImage and OpImageSparseXXX.

Disabled an invalid test.

6 years agoOptimize loads/stores on nested structs
GregF [Fri, 17 Nov 2017 23:47:11 +0000 (16:47 -0700)]
Optimize loads/stores on nested structs

Also fix LocalAccessChainConvert test: nested structs now convert

Add InsertExtractElim test for nested struct

6 years agoFix move semantics in iterator make_range
Andrey Tuganov [Mon, 20 Nov 2017 22:56:01 +0000 (17:56 -0500)]
Fix move semantics in iterator make_range

6 years agoAdd new compression algorithm and models
Andrey Tuganov [Tue, 14 Nov 2017 22:02:42 +0000 (17:02 -0500)]
Add new compression algorithm and models

Add new "short descriptor" algorithm to MARK-V codec.

Add three shader compression models:
lite - fast, poor compression
mid - balanced
max - best compression

6 years agoAdding an unique id to Instruction generated by IRContext
Alan Baker [Tue, 14 Nov 2017 19:11:50 +0000 (14:11 -0500)]
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
* Added an internal option to LinkerOptions to verify merged ids are
unique
* Added a test for the linker to verify merged ids are unique

* Updated MergeReturnPass to supply a context
* Updated DecorationManager to supply a context for cloned decorations

* Reworked several portions of the def use tests in anticipation of next
set of changes

6 years agoAdd dead function elimination to -O and -Os
Steven Perron [Fri, 17 Nov 2017 18:03:17 +0000 (13:03 -0500)]
Add dead function elimination to -O and -Os

This pass is very useful in reducing the size of the code, and reducing
the amount of work done by other optimizations.

6 years agoFix hard-coded header path
Lei Zhang [Fri, 17 Nov 2017 21:33:32 +0000 (16:33 -0500)]
Fix hard-coded header path

If SPIRV-Tools is used as an external project and have
googletest being kept in the same directory as it, we
won't have gmock-matchers.h in external/. This will
result in a compilation error.

Use gmock.h instead.

6 years agoGit should ignore external repos
David Neto [Wed, 15 Nov 2017 18:37:52 +0000 (13:37 -0500)]
Git should ignore external repos

Ignore googletest, spirv-headers, effcee, and re2

6 years agoAdd the decoration manager to the IRContext.
Steven Perron [Mon, 13 Nov 2017 20:31:43 +0000 (15:31 -0500)]
Add the decoration manager to the IRContext.

To make the decoration manger available everywhere, and to reduce the
number of times it needs to be build, I add one the IRContext.

As the same time, I move code that modifies decoration instruction into
the IRContext from mempass and the decoration manager.  This will make
it easier to keep everything up to date.

This should take care of issue #928.

6 years agoInitial implementation of merge return pass.
Alan Baker [Wed, 8 Nov 2017 21:22:10 +0000 (16:22 -0500)]
Initial implementation of merge return pass.

Works with current DefUseManager infrastructure.

Added merge return to the standard opts.

Added validation to passes.

Disabled pass for shader capabilty.

6 years agoAppveyor: skip building tags
Lei Zhang [Tue, 14 Nov 2017 14:18:42 +0000 (09:18 -0500)]
Appveyor: skip building tags

6 years agoAppveyor: Stop testing VS 2013/2015 Debug
Lei Zhang [Mon, 13 Nov 2017 19:55:20 +0000 (14:55 -0500)]
Appveyor: Stop testing VS 2013/2015 Debug

VS2017 Debug tests should suffice for intresting Debug cases.
This will save us ~30min of waiting time for each build job.

6 years agoAdd analysis to compute mappings between instructions and basic blocks.
Diego Novillo [Fri, 10 Nov 2017 14:39:00 +0000 (09:39 -0500)]
Add analysis to compute mappings between instructions and basic blocks.

This analysis builds a map from instructions to the basic block that
contains them.  It is accessed via get_instr_block().  Once built, it is kept
up-to-date by the IRContext, as long as instructions are removed via
KillInst.

I have not yet marked passes that preserve this analysis. I will do it
in a separate change.

Other changes:

- Add documentation about analysis values requirement to be powers of 2.
- Force a re-build of the def-use manager in tests.
- Fix AllPreserveFirstOnlyAfterPassWithChange to use the
  DummyPassPreservesFirst pass.
- Fix sentinel value for IRContext::Analysis enum.

- Fix logic for checking if the instr<->block mapping is valid in KillInst.

6 years agoFix decorations of inlined functions.
Daniel Schürmann [Tue, 24 Oct 2017 16:28:18 +0000 (18:28 +0200)]
Fix decorations of inlined functions.

Fixes issue #728.  Currently the inliner is not generating decorations for
inlined code which corresponds to function code which has decorations. An
example of decorations that are relevant: RelaxedPrecision, NoContraction.

The solution is to replicate the decoration during inlining.

6 years agoTests: Add optional dependency on Effcee stateful matcher
David Neto [Wed, 8 Nov 2017 05:23:42 +0000 (00:23 -0500)]
Tests: Add optional dependency on Effcee stateful matcher

Add Effcee as an optional dependency for use in tests.  In future it will
be a required dependency.

Effcee is a stateful pattern matcher that has much of the functionality
of LLVM's FileCheck, except in library form.  Effcee makes it much easier
to write tests for optimization passes.

Demonstrate its use in a test for the strength-reduction pass.

Update README.md with example commands of how to get sources.

Update Appveyor and Travis-CI build rules.

Also: Include test libraries if not SPIRV_SKIP_TESTS
- SPIRV_SKIP_TESTS is implied by SPIRV_SKIP_EXECUTABLES

6 years agoHave all MemPasses preserve the def-use manager.
Steven Perron [Thu, 9 Nov 2017 16:24:41 +0000 (11:24 -0500)]
Have all MemPasses preserve the def-use manager.

Originally the passes that extended from MemPass were those that are
of the def-use manager.  I am assuming they would be able to preserve
it because of that.

Added a check to verify consistency of the IRContext. The IRContext
relies on the pass to tell it if something is invalidated.
It is possible that the pass lied.  To help identify those situations,
we will check if the valid analyses are correct after each pass.

This will be enabled by default for the debug build, and disabled in the
production build.  It can be disabled in the debug build by adding
"-DSPIRV_CHECK_CONTEXT=OFF" to the cmake command.

6 years agoTravis: auto deploy build artifacts to GitHub Releases
Lei Zhang [Thu, 9 Nov 2017 00:41:17 +0000 (19:41 -0500)]
Travis: auto deploy build artifacts to GitHub Releases

Pushing a commit to the master branch will trigger a build on
Travis. If the build is successful, the artifacts will be
collected and pushed to GitHub Releases, under the "master-tot"
release.

6 years agoAppveyor: auto deploy build artifacts to GitHub Releases
Lei Zhang [Wed, 8 Nov 2017 21:44:53 +0000 (16:44 -0500)]
Appveyor: auto deploy build artifacts to GitHub Releases

Pushing a commit to the master branch will trigger a build on
Appveyor. If the build is successful, the artifacts will be
collected and pushed to GitHub Releases, under the "master-tot"
release.

6 years agoRe-format files in source, source/opt, source/util, source/val and tools.
Diego Novillo [Wed, 8 Nov 2017 17:40:02 +0000 (12:40 -0500)]
Re-format files in source, source/opt, source/util, source/val and tools.

NFC. This just makes sure every file is formatted following the
formatting definition in .clang-format.

Re-formatted with:

$ clang-format -i $(find source tools include -name '*.cpp')
$ clang-format -i $(find source tools include -name '*.h')