platform/upstream/SPIRV-Tools.git
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')

6 years agoAdd the IRContext (part 2): Add def-use manager
Steven Perron [Thu, 2 Nov 2017 18:25:48 +0000 (14:25 -0400)]
Add the IRContext (part 2): Add def-use manager

This change will move the instances of the def-use manager to the
IRContext.  This allows it to persists across optimization, and does
not have to be rebuilt multiple times.

Added test to ensure that the IRContext is validating and invalidating
the analyses correctly.

6 years agoOpt: Fix HasLoads to not report decoration as load.
GregF [Mon, 6 Nov 2017 18:25:24 +0000 (11:25 -0700)]
Opt: Fix HasLoads to not report decoration as load.

6 years agoOpt: Remove CommonUniformElimination from -O and -Os (for now)
GregF [Tue, 7 Nov 2017 00:00:44 +0000 (17:00 -0700)]
Opt: Remove CommonUniformElimination from -O and -Os (for now)

It is causing crashes for some drivers. Will try to re-enable it once
existing drivers are able to deal better with it.

6 years agoDescribe public_spirv_tools_dev@khronos.org mailing list
David Neto [Wed, 4 Oct 2017 21:02:39 +0000 (17:02 -0400)]
Describe public_spirv_tools_dev@khronos.org mailing list

6 years agoValidate storage class of target pointer for OpStore
Nuno Subtil [Wed, 1 Nov 2017 03:08:23 +0000 (20:08 -0700)]
Validate storage class of target pointer for OpStore

6 years agoMove class CFG from namespace opt to namespace ir.
Diego Novillo [Thu, 2 Nov 2017 15:51:07 +0000 (11:51 -0400)]
Move class CFG from namespace opt to namespace ir.

It makes more sense to have the CFG inside the ir name space, as it is
descriptive of the representation.

6 years agoAdd a new class opt::CFG to represent the CFG for the module.
Diego Novillo [Mon, 30 Oct 2017 21:42:26 +0000 (17:42 -0400)]
Add a new class opt::CFG to represent the CFG for the module.

This class moves some of the CFG-related functionality into a new
class opt::CFG.  There is some other code related to the CFG in the
inliner and in opt::LocalSingleStoreElimPass that should also be moved,
but that require more changes than this pure restructuring.

I will move those bits in a follow-up PR.

Currently, the CFG is computed every time a pass is instantiated, but
this should be later moved to the new IRContext class that @s-perron is
working on.

Other re-factoring:

- Add BasicBlock::ContinueBlockIdIfAny. Re-factored out of MergeBlockIdIfAny
- Rewrite IsLoopHeader in terms of GetLoopMergeInst.
- Run clang-format on some files.

6 years agoAdd the IRContext (part 1)
Steven Perron [Mon, 30 Oct 2017 15:13:24 +0000 (11:13 -0400)]
Add the IRContext (part 1)

This is the first part of adding the IRContext.  This class is meant to
hold the extra data that is build on top of the module that it
owns.

The first part will simply create the IRContext class and get it passed
to the passes in place of the module.  For now it does not have any
functionality of its own, but it acts more as a wrapper for the module.

The functions that I added to the IRContext are those that either
traverse the headers or add to them.  I did this because we may decide
to have other ways of dealing with these sections (for example adding a
type pool, or use the decoration manager).

I also added the function that add to the header because the IRContext
needs to know when an instruction is added to update other data
structures appropriately.

Note that there is still lots of work that needs to be done.  There are
still many places that change the module, and do not inform the context.
That will be the next step.

6 years agoAdd validation for OpBranchConditional
Nuno Subtil [Thu, 26 Oct 2017 20:20:32 +0000 (13:20 -0700)]
Add validation for OpBranchConditional

6 years agoLowered initial capacity of move-to-front sequence
Andrey Tuganov [Mon, 30 Oct 2017 17:17:58 +0000 (13:17 -0400)]
Lowered initial capacity of move-to-front sequence

Also fixed outdated comments.

6 years agoFix copyright check when the build directory is in the source directory.
Steven Perron [Mon, 30 Oct 2017 19:31:19 +0000 (15:31 -0400)]
Fix copyright check when the build directory is in the source directory.

The IDE I am using places the cmake build directory inside the source
directory.  When that happens the copyright check fails because the
build process creates a file CMakeCXXCompilerId.cpp.  That file does
not have the copyright information, so the test fails.

I want this file to be ignored, so I added its directory, CompilerIdCXX,
to the list of directories to be ignored.

6 years agoADCE: Dead if elimination
GregF [Tue, 17 Oct 2017 22:33:43 +0000 (16:33 -0600)]
ADCE: Dead if elimination

Mark structured conditional branches live only if one or more instructions
in their associated construct is marked live. After closure, replace dead
structured conditional branches with a branch to its merge and remove
dead blocks.

ADCE: Dead If Elim: Remove duplicate StructuredOrder code

Also generalize ComputeStructuredOrder so that the caller can specify the
root block for the order. Phi insertion uses pseudo_entry_block and adce and
dead branch elim use the first block of the function.

ADCE: Dead If Elim: Pull redundant code out of InsertPhiInstructions

ADCE: Dead If Elim: Encapsulate CFG Cleanup Initialization

ADCE: Dead If Elim: Remove redundant code from ADCE initialization

ADCE: Dead If: Use CFGCleanup to eliminate newly dead blocks

Moved bulk of CFG Cleanup code into MemPass.

6 years agoMore re-factoring to simplify pass initialization.
Diego Novillo [Mon, 30 Oct 2017 13:02:03 +0000 (09:02 -0400)]
More re-factoring to simplify pass initialization.

This implements two cleanups suggested by @s-perron
(https://github.com/KhronosGroup/SPIRV-Tools/pull/921):

- Move FindNamedOrDecoratedIds() into MemPass::InitializeProcessing().
- Remove FinalizeNextId(). Always call SetIdBound() from
  Pass::TakeNextId().

6 years agoAdd option to relax validation of store types.
Steven Perron [Tue, 24 Oct 2017 19:13:13 +0000 (15:13 -0400)]
Add option to relax validation of store types.

There are a number of users of spriv-opt that are hitting errors
because of stores with different types.  In general, this is wrong, but,
in these cases, the types are the exact same except for decorations.

The options is "--relax-store-struct", and it can be used with the
validator or the optimizer.

We assume that if layout information is missing it is consistent.  For
example if one struct has a offset of one of its members, and the other
one does not, we will still consider them as being layout compatible.
The problem will be if both struct has and offset decoration for
corresponding members, and the offset are different.

6 years agoCompression: removed 'presumed index' feature
Andrey Tuganov [Fri, 27 Oct 2017 15:31:39 +0000 (11:31 -0400)]
Compression: removed 'presumed index' feature

The feature used to improve compression of const integers which were
presumed to be indices. Now obsolete as descriptor-based compression
does this in a more generalized way.

6 years agoUse std::lower_bound for opcode lookup
Jesus Carabano [Fri, 27 Oct 2017 12:28:50 +0000 (15:28 +0300)]
Use std::lower_bound for opcode lookup

Use std::lower_bound for opcode-to-string

Stable sort the generated instruction table.

6 years agoRe-factor Phi insertion code out of LocalMultiStoreElimPass
Diego Novillo [Wed, 25 Oct 2017 17:26:25 +0000 (13:26 -0400)]
Re-factor Phi insertion code out of LocalMultiStoreElimPass

Including a re-factor of common behaviour into class Pass:

The following functions are now in class Pass:

- IsLoopHeader.
- ComputeStructuredOrder
- ComputeStructuredSuccessors (annoyingly, I could not re-factor all
  instances of this function, the copy in common_uniform_elim_pass.cpp
  is slightly different and fails with the common implementation).
- GetPointeeTypeId
- TakeNextId
- FinalizeNextId
- MergeBlockIdIfAny

This is a NFC (non-functional change)

6 years agoChange the sections in the module to use the InstructionList class.
Steven Perron [Fri, 13 Oct 2017 18:25:21 +0000 (14:25 -0400)]
Change the sections in the module to use the InstructionList class.

This change will replace a number of the
std::vector<std::unique_ptr<Instruction>> member of the module to
InstructionList.  This is for consistency and to make it easier to
delete instructions that are no longer needed.

6 years agoTurn all function static non-POD variables into global POD variables
Lei Zhang [Wed, 25 Oct 2017 16:15:51 +0000 (12:15 -0400)]
Turn all function static non-POD variables into global POD variables

Function static non-POD data causes problems with DLL lifetime.
This pull request turns all static info tables into strict POD
tables. Specifically, the capabilities/extensions field of
opcode/operand/extended-instruction table are turned into two
fields, one for the count and the other a pointer to an array of
capabilities/extensions. CapabilitySet/EnumSet are not used in
the static table anymore, but they are still used for checking
inclusion by constructing on the fly, which should be cheap for
the majority cases.

Also moves all these tables into the global namespace to avoid
C++11 function static thread-safe initialization overhead.

6 years agoValidate SpvOpVectorShuffle
Józef Kucia [Fri, 13 Oct 2017 19:53:58 +0000 (21:53 +0200)]
Validate SpvOpVectorShuffle

6 years agorestrict opcodes targeting OpDecorationGroup
Jesus Carabano [Sat, 21 Oct 2017 16:39:32 +0000 (19:39 +0300)]
restrict opcodes targeting OpDecorationGroup

6 years agoFixed --eliminate-common-uniform so that it does not eliminate loads of volatile...
Daniel Schürmann [Tue, 24 Oct 2017 11:24:08 +0000 (13:24 +0200)]
Fixed --eliminate-common-uniform so that it does not eliminate loads of volatile variables.

6 years agoOptimizer: Line and NoLine are not debug1 or debug2
David Neto [Mon, 23 Oct 2017 14:53:28 +0000 (10:53 -0400)]
Optimizer: Line and NoLine are not debug1 or debug2

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

6 years agoRefactored compression debugger
Andrey Tuganov [Tue, 17 Oct 2017 21:38:04 +0000 (17:38 -0400)]
Refactored compression debugger

Markv codec now receives two optional callbacks:
LogConsumer for internal codec logging
DebugConsumer for testing if encoding->decoding produces the original
results.

6 years agoRun dead variable elimination when using -O and -Os
Steven Perron [Mon, 23 Oct 2017 19:48:29 +0000 (15:48 -0400)]
Run dead variable elimination when using -O and -Os

We want to run the optimization when using -O and -Os, but it was not
added at part of https://github.com/KhronosGroup/SPIRV-Tools/pull/905.
This change will add that a well as some minor formatting changes
requested in that same pull request.

6 years agoDeadBranchElim: Fix dead block elimination
GregF [Mon, 16 Oct 2017 23:30:52 +0000 (17:30 -0600)]
DeadBranchElim: Fix dead block elimination

The previous algorithm would leave invalid code in the case of unreachable
blocks pointing into a dead branch. It would leave the unreachable blocks
branching to labels that no longer exist. The previous algorithm also left
unreachable blocks in some cases (a loop following an orphaned merge block).
This fix also addresses that.

This code will soon be replaced with the coming CFG cleanup.

6 years agoAdd pass to remove dead variables at the module level.
Steven Perron [Fri, 20 Oct 2017 16:17:41 +0000 (12:17 -0400)]
Add pass to remove dead variables at the module level.

There does not seem to be any pass that remove global variables.  I
think we could use one.  This pass will look specifically for global
variables that are not referenced and are not exported.  Any decoration
associated with the variable will also be removed.  However, this could
cause types or constants to become unreferenced.  They will not be
removed.  Another pass will have to be called to remove those.

6 years agoOptimizer: OpModuleProcessed is in its own layout section
David Neto [Fri, 20 Oct 2017 22:04:20 +0000 (18:04 -0400)]
Optimizer: OpModuleProcessed is in its own layout section

This is a recent decision from the SPIR WG.  The spec update
has not yet been published.
Khronos SPIR-V internal issue 199

6 years agoAdd Android.mk build to Travis CI
Andrey Tuganov [Thu, 19 Oct 2017 20:02:47 +0000 (16:02 -0400)]
Add Android.mk build to Travis CI

Added NDK_LIBS_OUT

6 years agoAdded dummy android test application
Andrey Tuganov [Fri, 20 Oct 2017 18:34:32 +0000 (14:34 -0400)]
Added dummy android test application

The application is needed to test Android.mk build.

6 years agoFix cfg_cleanup.cpp. My bad.
David Neto [Fri, 20 Oct 2017 20:51:20 +0000 (16:51 -0400)]
Fix cfg_cleanup.cpp.  My bad.

6 years agoRemove coding redundancy in cfg_cleanup_pass.cpp
David Neto [Thu, 19 Oct 2017 19:56:23 +0000 (15:56 -0400)]
Remove coding redundancy in cfg_cleanup_pass.cpp

6 years agoAdd instruction_list to Android.mk
Andrey Tuganov [Fri, 20 Oct 2017 18:38:50 +0000 (14:38 -0400)]
Add instruction_list to Android.mk

6 years agoAdd validation pass for conversion instructions
Andrey Tuganov [Thu, 28 Sep 2017 18:53:24 +0000 (14:53 -0400)]
Add validation pass for conversion instructions

The pass checks correctness of operands of instruction in opcode range
OpConvertFToU - OpBitset.

Disabled invalid tests

Disabled UConvert validation until Vulkan CTS can catch up.

Add validate_conversion to Android.mk

Also remove duplicate entry in CMakeLists.txt.

6 years agoChange BasicBlock to use InstructionList to hold instructions.
Steven Perron [Fri, 13 Oct 2017 18:25:21 +0000 (14:25 -0400)]
Change BasicBlock to use InstructionList to hold instructions.

This is the first step in replacing the std::vector of Instruction
pointers to using and intrusive linked list.

To this end, we created the InstructionList class.  It inherites from
the IntrusiveList class, but add the extra concept of ownership.  An
InstructionList owns the instruction that are in it.  This is to be
consistent with the current ownership rules where the vector owns the
instruction that are in it.

The other larger change is that the inst_ member of the BasicBlock class
was changed to using the InstructionList class.

Added test for the InsertBefore functions, and making sure that the
InstructionList destructor will delete the elements that it contains.

I've also add extra comments to explain ownership a little better.

6 years agoRemoved todos from validate_id.cpp
Andrey Tuganov [Thu, 19 Oct 2017 17:00:52 +0000 (13:00 -0400)]
Removed todos from validate_id.cpp

Removed todos for validation of opcodes handles in other passes.

6 years agoDeadBranchElim: Slightly more defensive coding
David Neto [Thu, 12 Oct 2017 16:21:26 +0000 (12:21 -0400)]
DeadBranchElim: Slightly more defensive coding

6 years agoThe reviewed cfg_cleanup optimize pass
David Neto [Thu, 19 Oct 2017 19:22:02 +0000 (15:22 -0400)]
The reviewed cfg_cleanup optimize pass

6 years agoCFG cleanup pass - Remove unreachable blocks.
Diego Novillo [Wed, 6 Sep 2017 12:56:41 +0000 (08:56 -0400)]
CFG cleanup pass - Remove unreachable blocks.

- Adds a new pass CFGCleanupPass.  This serves as an umbrella pass to
  remove unnecessary cruft from a CFG.
- Currently, the only cleanup operation done is the removal of
  unreachable basic blocks.
- Adds unit tests.
- Adds a flag to spirvopt to execute the pass (--cfg-cleanup).

6 years agoAndroid.mk: add source/opt/fold.cpp
David Neto [Wed, 18 Oct 2017 14:28:12 +0000 (10:28 -0400)]
Android.mk: add source/opt/fold.cpp

6 years agoMerge pull request #885 from dnovillo/const-prop
Diego Novillo [Wed, 18 Oct 2017 12:37:00 +0000 (08:37 -0400)]
Merge pull request #885 from dnovillo/const-prop

Re-factor generic constant folding code out of fold spec constants pass

6 years agoRe-factor generic constant folding code out of FoldSpecConstantOpAndCompositePass
Diego Novillo [Tue, 17 Oct 2017 23:41:37 +0000 (19:41 -0400)]
Re-factor generic constant folding code out of FoldSpecConstantOpAndCompositePass

There are no functional changes in this patch.  The generic folding
routines in FoldSpecConstantOpAndCompositePass are now inside opt/fold.{cpp,h}.
This code will be used by the upcoming constant propagation pass.  In
time, we'll add more expression folding and simplification into these
two files.

6 years agoADCE: Treat privates like locals in entry point with no calls
GregF [Tue, 10 Oct 2017 20:35:53 +0000 (14:35 -0600)]
ADCE: Treat privates like locals in entry point with no calls

This is needed for ongoing legalization of HLSL. It allows removal
of accesses to textures/buffers that are not used.

6 years agoOpt: Move *NextId functionality into MemPass
GregF [Tue, 10 Oct 2017 23:16:50 +0000 (17:16 -0600)]
Opt: Move *NextId functionality into MemPass

6 years agoValidator: Test OpReturnValue type check
David Neto [Thu, 12 Oct 2017 19:20:29 +0000 (15:20 -0400)]
Validator: Test OpReturnValue type check

The check already existed.  I added a test for it.

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

6 years agoReenable validate type unique pass
Andrey Tuganov [Wed, 11 Oct 2017 15:34:38 +0000 (11:34 -0400)]
Reenable validate type unique pass

Vulkan CTS patch fixing the instances of non-unique type declaration in
autogenerated code has recently been submitted.

6 years agoRefactored MARK-V API
Andrey Tuganov [Tue, 3 Oct 2017 21:36:37 +0000 (17:36 -0400)]
Refactored MARK-V API

- switched from C to C++
- moved MARK-V model creation from backend to frontend
- The same MARK-V model object can be used to encode/decode multiple
files
- Added MARK-V model factory (currently only one option)
- Added --validate option to spirv-markv (run validation while
encoding/decoding)

6 years agoValidator checks OpReturn called from void func
Andrey Tuganov [Wed, 11 Oct 2017 22:13:21 +0000 (18:13 -0400)]
Validator checks OpReturn called from void func

Added check into validate_cfg which checks that OpReturn is not called
from functions which are supposed to return a value.

6 years agoGeneric intrusive linked list class.
Steven Perron [Tue, 10 Oct 2017 13:47:01 +0000 (09:47 -0400)]
Generic intrusive linked list class.

This commit is the initial implementation of the intrusive linked list
class.  It includes the implementation in the header files, and unit
test.

The iterators are circular: incrementing end() gives begin() and
decrementing begin() gives end().  Also made it valid to
decrement end().

Expliticly defines move constructor and move assignment
- Visual Studio 2013 does not implicitly generate the move constructor or
  move assignments.  So they need to be explicit, otherwise it will try to
  use the copy constructor, which we explicitly deleted.
- Can't use "= default" either.
  Seems like VS2013 does not support explicitly using the default move
  constructors and move assignments, so I wrote them out.

6 years agoDeadBranchElim: Add dead case elimination
GregF [Fri, 6 Oct 2017 02:37:00 +0000 (20:37 -0600)]
DeadBranchElim: Add dead case elimination

Expands dead branch elimination to eliminate dead switch cases. It also
changes dbe to eliminate orphaned merge blocks and recursively eliminate
any blocks thereby orphaned.

6 years agoAdd Android.mk to SPIRV-Tools
Andrey Tuganov [Thu, 5 Oct 2017 23:07:31 +0000 (19:07 -0400)]
Add Android.mk to SPIRV-Tools

Android.mk was migrated from shaderc/third_party.

android_test is a stub, only builds spirv-tools libs.h to test build.

6 years agoAdd -O, -Os and -Oconfig flags.
Diego Novillo [Wed, 30 Aug 2017 18:19:22 +0000 (14:19 -0400)]
Add -O, -Os and -Oconfig flags.

These flags are expanded to a series of spirv-opt flags with the
following semantics:

-O: expands to passes that attempt to improve the performance of the
    generated code.

-Os: expands to passes that attempt to reduce the size of the generated
     code.

-Oconfig=<file> expands to the sequence of passes determined by the
                flags specified in the user-provided file.

6 years agoSet cmake-policy CMP0048 to NEW
Tim Diekmann [Tue, 10 Oct 2017 12:23:42 +0000 (14:23 +0200)]
Set cmake-policy CMP0048 to NEW

6 years agoImplement Linker (module combiner)
Pierre Moreau [Thu, 13 Jul 2017 00:16:51 +0000 (02:16 +0200)]
Implement Linker (module combiner)

Add extra iterators for ir::Module's sections
Add extra getters to ir::Function
Add a const version of BasicBlock::GetLabelInst()

Use the max of all inputs' version as version

Split debug in debug1 and debug2
- Debug1 instructions have to be placed before debug2 instructions.

Error out if different addressing or memory models are found

Exit early if no binaries were given

Error out if entry points are redeclared

Implement copy ctors for Function and BasicBlock
- Visual Studio ends up generating copy constructors that call deleted
  functions while compiling the linker code, while GCC and clang do not.
  So explicitly write those functions to avoid Visual Studio messing up.

Move removing duplicate capabilities to its own pass

Add functions running on all IDs present in an instruction

Remove duplicate SpvOpExtInstImport

Give default options value for link functions

Remove linkage capability if not making a library

Check types before allowing to link

Detect if two types/variables/functions have different decorations

Remove decorations of imported variables/functions and their types

Add a DecorationManager

Add a method for removing all decorations of id

Add methods for removing operands from instructions

Error out if one of the modules has a non-zero schema

Update README.md to talk about the linker

Do not freak out if an imported built-in variable has no export

6 years agoRemove duplicate dead branch elim pass declaration
Andrey Tuganov [Thu, 5 Oct 2017 20:26:09 +0000 (16:26 -0400)]
Remove duplicate dead branch elim pass declaration

The function had two declarations in the same header with somewhat
different comments.

6 years agoHack around bug in gcc-4.8.1 templates.
Andrew Woloszyn [Thu, 5 Oct 2017 15:01:34 +0000 (11:01 -0400)]
Hack around bug in gcc-4.8.1 templates.

This keeps the previous behavior for other compilers that will
throw warnings on a negative shift operation, but works around
the internal compiler error in GCC.

6 years agoAggressiveDCE: Fix to not treat parameter memory refs as local
GregF [Fri, 29 Sep 2017 22:22:39 +0000 (16:22 -0600)]
AggressiveDCE: Fix to not treat parameter memory refs as local

This fixes a bug that incorrectly deletes stores to parameters, which
can be used to return values from functions.

6 years agoCompact-ids pass should update the header ID bound
Pierre Moreau [Sun, 1 Oct 2017 19:47:44 +0000 (21:47 +0200)]
Compact-ids pass should update the header ID bound

6 years agoDiagnosticStream move ctor moves output duties to new object
David Neto [Sun, 1 Oct 2017 13:27:00 +0000 (09:27 -0400)]
DiagnosticStream move ctor moves output duties to new object

- Take over contents of the expiring message stream
- Prevent the expiring object from emitting anything during destruction

6 years agoCache end iterators for speed
David Neto [Thu, 28 Sep 2017 15:14:00 +0000 (11:14 -0400)]
Cache end iterators for speed

Helps scaling of DefUseManager on modules with many thousands
of instructions.

6 years agoNo use to check OpBitCount result width
jcaraban [Fri, 29 Sep 2017 05:55:41 +0000 (08:55 +0300)]
No use to check OpBitCount result width

6 years agoSkip checking copyright if SPIRV_SKIP_TESTS is enabled
Lei Zhang [Thu, 28 Sep 2017 01:22:05 +0000 (21:22 -0400)]
Skip checking copyright if SPIRV_SKIP_TESTS is enabled

6 years agoUpdate CHANGES to reflect fix for #827
David Neto [Wed, 27 Sep 2017 14:03:20 +0000 (10:03 -0400)]
Update CHANGES to reflect fix for #827

6 years agoCompact-ids pass should update instruction's result_id member
David Neto [Tue, 26 Sep 2017 22:05:27 +0000 (18:05 -0400)]
Compact-ids pass should update instruction's result_id member

Also update the result type field.

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

6 years agoRemove duplicated declaration of CreateAggressiveDCEPass().
Lei Zhang [Tue, 26 Sep 2017 17:55:23 +0000 (13:55 -0400)]
Remove duplicated declaration of CreateAggressiveDCEPass().

6 years agoAdd bitwise operations validator pass
Andrey Tuganov [Mon, 18 Sep 2017 20:49:11 +0000 (16:49 -0400)]
Add bitwise operations validator pass

The pass checks correctness of operand types of all bitwise instructions
(opcode range from SpvOpShiftRightLogical to SpvOpBitCount).

6 years agoAdd remaining opcodes to arithmetics validation
Andrey Tuganov [Mon, 18 Sep 2017 17:06:40 +0000 (13:06 -0400)]
Add remaining opcodes to arithmetics validation

Add validation rules for:
- OpIAddCarry
- OpISubBorrow
- OpUMulExtended
- OpSMulExtended

Includes some refactoring of old code.

6 years agoUpdate CHANGES with recent news
David Neto [Tue, 26 Sep 2017 15:30:57 +0000 (11:30 -0400)]
Update CHANGES with recent news

6 years agoCreate the dead function elimination pass
Steven Perron [Tue, 19 Sep 2017 14:12:13 +0000 (10:12 -0400)]
Create the dead function elimination pass

Creates a pass called eliminate dead functions that looks for functions
that could never be called, and deletes them from the module.

To support this change a new function was added to the Pass class to
traverse the call trees from diffent starting points.

Includes a test to ensure that annotations are removed when deleting a
dead function.  They were not, so fixed that up as well.

Did some cleanup of the assembly for the test in pass_test.cpp.  Trying
to make them smaller and easier to read.

6 years agoDetach MARK-V from the validator
Andrey Tuganov [Mon, 25 Sep 2017 18:55:44 +0000 (14:55 -0400)]
Detach MARK-V from the validator

MARK-V codec was previously dependent on the validation state.
Now it doesn't need the validator to function, but can still optionally
create it and validate every instruction once it's decoded.

6 years agoAvoid using global static variables
Lei Zhang [Thu, 21 Sep 2017 21:24:57 +0000 (17:24 -0400)]
Avoid using global static variables

Previously we have several grammar tables defined as global static
variables and these grammar table entries contains non-POD struct
fields (CapabilitySet/ExtensionSet). The initialization of these
non-POD struct fields may require calling operator new. If used
as a library and the caller defines its own operator new, things
can screw up.

This pull request changes all global static variables into
function static variables, which is lazy evaluated in a thread
safe way as guaranteed by C++11.