summaryrefslogtreecommitdiff
path: root/source
AgeCommit message (Collapse)AuthorFilesLines
2018-07-27Add API to create passes out of a list of command-line flags.Diego Novillo1-4/+238
This re-implements the -Oconfig=<file> flag to use a new API that takes a list of command-line flags representing optimization passes. This moves the processing of flags that create new optimization passes out of spirv-opt and into the library API. Useful for other tools that want to incorporate a facility similar to -Oconfig. The main changes are: 1- Add a new public function Optimizer::RegisterPassesFromFlags. This takes a vector of strings. Each string is assumed to have the form '--pass_name[=pass_args]'. It creates and registers into the pass manager all the passes specified in the vector. Each pass is validated internally. Failure to create a pass instance causes the function to return false and a diagnostic is emitted to the registered message consumer. 2- Re-implements -Oconfig in spirv-opt to use the new API.
2018-07-20Handle undef literal value in vector shuffleAlan Baker2-2/+17
Fixes #1731 * Updated folding rules related to vector shuffle to account for the undef literal value: * FoldVectorShuffleFeedingShuffle * FoldVectorShuffleFeedingExtract * FoldVectorShuffleWithConstants * These rules would commit memory violations due to treating the undef literal value as an accessible composite component
2018-07-20Replace opt::Instruction type and result cache with flags. (#1718)dan sinclair2-39/+57
Currentlty opt::Instruction class holds a cache of the result_id and type_id for the instruction. That cache needs to be updated if the underlying operand values are changes. This CL changes the cache to being a flag if there is a type or result id for the instruction. We then retrieve the value if needed from the operands.
2018-07-19Add variable pointer support to IsValidBasePointerAlan Baker2-7/+27
Fixes #1729 * Adds supported opcodes to IsValidBasePointer() enable by VariablePointers and VariablePointersStorageBuffer capabilities * Added tests
2018-07-19Fix block ordering in dead branch elimAlan Baker3-0/+63
Fixes #1727 * If the pass finds any dead branches it can optimize then at the end of the pass it reorders basic blocks to ensure they satisfy block ordering requirements * Added some new tests * While investigating this issue, found and fixed a non-deterministic ordering of dominators * Now the edges used to construct the dominator tree are sorted according to posorder traversal indices
2018-07-16Fixup line number for OpVectorShuffle ID error.Dan Sinclair1-3/+3
This CL updates the code to pull a valid instruction for the line number when outputting a component error in OpVectorShuffle. The error line isn't the best at this point as it points at the component, but it's better then a -1 (turning to max<size_t>) that was being output. The error messages has been updated to better reflect what the error is attempting to say. Issue 1719.
2018-07-16Fix finding constant with particular type. (#1724)Steven Perron3-11/+49
With current implementation, the constant manager does not keep around two constant with the same value but different types when the types hash to the same value. So when you start looking for that constant you will get a constant with the wrong type back. I've made a few changes to the constant manager to fix this. First off, I have changed the map from constant to ids to be an std::multimap. This way a single constant can be mapped to mutiple ids each representing a different type. Then when asking for an id of a constant, we can search all of the ids associated with that constant in order to find the one with the correct type.
2018-07-13Fix infinite loop while folding OpVectorShuffle (#1722)Steven Perron1-1/+6
When folding an OpVectorShuffle where the first operand is defined by an OpVectorShuffle, is unused, and is equal to the second, we end up with an infinite loop. This is because we think we change the instruction, but it does not actually change. So we keep trying to folding the same instruction. This commit fixes up that specific issue. When the operand is unused, we replace it with Null.
2018-07-13Fix size error when folding vector shuffle. (#1721)Steven Perron2-1/+17
When folding a vector shuffle that feeds another vector shuffle causes the size of the first operand to change, when other indices have to be adjusted reletive to the new size.
2018-07-12Remove dead code (#1720)dan sinclair1-437/+0
Remove commented out code from validate_id.
2018-07-12Cleanup extraneous namespace qualifies in source/opt. (#1716)dan sinclair144-3412/+3146
This CL follows up on the opt namespacing CLs by removing the unnecessary opt:: and opt::analysis:: namespace prefixes.
2018-07-12Remove the module from opt::Function. (#1717)dan sinclair8-19/+8
The function class provides a {Set|Get}Parent call in order to provide the context to the LoopDescriptor methods. This CL removes the module from Function and provides the needed context directly to LoopDescriptor on creation.
2018-07-12Cleanup CFG header. (#1715)dan sinclair2-16/+3
This CL removes some unused methods from CFG, makes the constructor explicit and moves the using statement to the cpp file where it's used.
2018-07-12Cleanup some pass code to get context directly. (#1714)dan sinclair3-7/+6
Instead of going through the instruction we can access the context() directly from the pass. Issue #1703
2018-07-12Remove context() method from opt::Function (#1700)dan sinclair7-17/+13
This CL removes the context() method from opt::Function. In the places where the context() was used we can retrieve, or provide, the context in another fashion.
2018-07-12Pass the IRContext into the folding rules. (#1709)dan sinclair7-91/+63
This CL updates the folding rules to receive the IRContext as a paramter instead of retrieving off of the Instruction. Issue #1703
2018-07-12use Pass::Run to set the context on each pass. (#1708)dan sinclair96-400/+263
Currently the IRContext is passed into the Pass::Process method. It is then up to the individual pass to store the context into the context_ variable. This CL changes the Run method to store the context before calling Process which no-longer receives the context as a parameter.
2018-07-11Add option to skip verifying block layoutLei Zhang3-1/+11
We need this to avoid emitting errors on DirectX layout rules.
2018-07-11Add folding rule to merge a vector shuffle feeding another one.Steven Perron1-59/+164
2018-07-11Enforce block layout rules even when relaxedDavid Neto3-12/+50
- Vulkan 1.0 uses strict layout rules - Vulkan 1.0 with relaxed-block-layout validator option enforces all rules except for the relaxation of vector offset. - Vulkan 1.1 and later always supports relaxed block layout Add spot check tests for the relaxed-block-layout scenarios. Fixes #1697
2018-07-11Move validation files to val/ directory (#1692)dan sinclair29-209/+207
This CL moves the various validate files into the val/ directory with the rest of the validation infrastructure. This matches how opt/ is setup with the passes with the infrastructure.
2018-07-11Move tests into namespaces (#1689)dan sinclair1-2/+3
This CL moves the test into namespaces based on their directories.
2018-07-10Vulkan permits non-monotonic offsets for block membersDavid Neto3-8/+47
Other environments do not. Add tests for OpenGL 4.5 and SPIR-V universal 1.0 to ensure they still check monotonic layout. For universal 1.0, we're assuming it otherwise follows Vulkan rules for block layout. Fixes #1685
2018-07-10Use spv_result_t instead of boolArseny Kapoulkine1-1/+1
Using bool is confusing here, and results in an MSVC warning about an implicit cast to bool.
2018-07-10Fix up code to make ClangTidy happy.Steven Perron2-12/+12
Just a few changes to pass `std::function` objects by const reference instead of by value.
2018-07-10Cleanup whitespace lint warnings. (#1690)dan sinclair5-16/+14
This CL cleans up the whitespace warnings and enables the check when running 'git cl presubmit --all -uf'.
2018-07-10Convert validation to use libspriv::Instruction where possible. (#1663)dan sinclair24-461/+343
For the instructions which execute after the IdPass check we can provide the Instruction instead of the spv_parsed_instruction_t. This Instruction class provides a bit more context (like the source line) that is not available from spv_parsed_instruction_t.
2018-07-09Move the validation code into the val:: namespace (#1682)dan sinclair39-110/+172
This CL moves the validation code to the val:: namespace. This makes it clearer which instance of the Instruction and other classes are being referred too.
2018-07-09Move link/ code to anonymous namespace (#1679)dan sinclair1-159/+162
Most of the link code is marked as static. This CL introduces an anonymous namespace and removes the static methods. The last two methods are exposed in the public API and have been left in the spvtools namespace.
2018-07-09Move the ir namespace to opt. (#1680)dan sinclair163-3240/+3289
This CL moves the files in opt/ to consistenly be under the opt:: namespace. This frees up the ir:: namespace so it can be used to make a shared ir represenation.
2018-07-07Change libspirv to spvtools namespace (#1678)dan sinclair85-458/+378
This CL changes all of the libspirv namespace code to spvtools to match the rest of the code base.
2018-07-06Move utils/ to spvtools::utilsdan sinclair25-116/+141
Currently the utils/ folder uses both spvutils:: and spvtools::utils. This CL changes the namespace to consistenly be spvtools::utils to match the rest of the codebase.
2018-07-06Move comp code into comp namespacedan sinclair3-2/+7
This CL moves the code in the comp/ directories into the comp namespace.
2018-07-06validator: use RowMajor, ArrayStride, MatrixStrideDavid Neto1-44/+233
Implement rules for row-major matrices Use ArrayStride and MatrixStride to compute sizes Propagate matrix stride and RowMajor/ColumnMajor through array members of structs. Fixes #1637 Fixes #1668
2018-07-06Layout validation: Permit {vec3; float} tight packingDavid Neto1-2/+7
Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/1666
2018-07-06Add a check for invalid exits from case construct.Alan Baker1-10/+23
Fixes #1618. Adds a check that validates acceptable exits from case constructs. Case constructs may only exit to another case construct, the corresponding merge, an outer loop continue or outer loop merge.
2018-07-06Fix layout checks for StorageBuffer and PushConstant storage classesDavid Neto1-58/+82
Fixes #1664 : PushConstant with Block follows storage buffer rules PushConstant variables were being checked with block rules, which are too strict. Fixes #1606 : StorageBuffer with Block layout follows buffer rules StorageBuffer variables were not being checked before. Fix layout messages: say storage class and decoration We need to provide more information about storage class and decoration.
2018-07-05Move folding routines into a classSteven Perron11-195/+250
The folding routines are currently global functions. They also rely on data in an std::map that holds the folding rules for each opcode. This causes that map to not have a clear owner, and therefore never gets deleted. There has been a request to delete this map. To implement this, we will create a InstructionFolder class that owns the maps. The IRContext will own the InstructionFolder instance. Then the global functions will become public memeber functions of the InstructionFolder. Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/1659.
2018-07-05Make sure the constant folder get the correct type.Steven Perron7-11/+31
There are a few locations where we need to handle duplicate types. We cannot merge them because they may be needed for reflection. When this happens we need do some extra lookups in the type manager. The specific fixes are: 1) When generating a constant through `GetDefiningInstruction` accept and use an id for the desired type of the constant. This will make sure you get the type that is needed. 2) In Private-to-local, make sure we to update the def-use chains when a new pointer type is created. 3) In the type manager, make sure that `FindPointerToType` returns a pointer that points to the given type and not a duplicate type. 4) In scalar replacment, make sure the null constants that are created are the correct type.
2018-07-04Add private to local to optimization and size passes.Steven Perron1-0/+2
Many optimization will run on function scope symbols only. When symbols are moved from private scope to function scople, then these optimizations can do more. I believe it is a good idea to run this pass with both -O and -Os. To get the most out of it it should be run ASAP after inlining and something that remove all of the dead functions.
2018-07-03Support SPV_KHR_8bit_storageDavid Neto3-2/+12
- Add asm/dis test for SPV_KHR_8bit_storage - validator: SPV_KHR_8bit_storage capabilities enable declaration of 8bit int TODO: - validator: ban arithmetic on 8bit unless Int8 is enabled Covered by https://github.com/KhronosGroup/SPIRV-Tools/issues/1595
2018-07-03Produce better error diagnostics in the CFG validation. (#1660)dan sinclair7-29/+57
Produce better error diagnostics in the CFG validation. This CL fixes up several issues with the diagnostic error line output in the CFG validation code. For the cases where we can determine a better line it has been output. For other cases, we removed the diagnostic line and the error line number from the results. Fixes #1657
2018-06-29Revert change and stop running remove duplicates.Steven Perron3-69/+6
Revert "Don't merge types of resources" This reverts commit f393b0e48014867eaada2044841cd7e0140b3d0d, but leaves the tests that were added. Added new test. These test are the so that, if someone tries the same change I made, they will see the test that they need to handle. Don't run remove duplicates in -O and -Os Romve duplicates was run to help reduce compile time when looking for types in the type manager. I've run compile time test on three sets of shaders, and the compile time does not seem to change. It should be safe to remove it.
2018-06-29Remove stores of undef.Steven Perron2-1/+37
When storing an undef, any value is valid, including the one already in that memory location. So we can avoid the store.
2018-06-28GLSL.std.450 Refract Eta can be any float scalarDavid Neto1-4/+2
This is a decision from Khronos-internal SPIR-V spec issue 337.
2018-06-27Fix assert during compact IDs pass (#1649)Greg Roth1-3/+1
During the compact IDs optimization pass, the result IDs of some basic blocks can change. In spite of this, GetPreservedAnalyses indicated that the CFG was preserved. But the CFG relies on the basic blocks having the same IDs. Simply removing this flag resolves the issue by preventing the CFG check. Also Removes combinators and namemap preserved analyses from compact IDs pass.
2018-06-27Don't merge types of resourcesSteven Perron2-4/+65
When doing reflection users care about the names of the variable, the name of the type, and the name of the members. Remove duplicates breaks this because it removes the names one of the types when merging. To fix this we have to keep the different types around for each resource. This commit adds code to remove duplicates to look for the types uses to describe resources, and make sure they do not get merged. However, allow merging of a type used in a resource with something not used in a resource. Was done when the non resource type came second. This could have a negative effect on compile time, but it was not expected to be much. Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/1372.
2018-06-27validator: Fix storage buffer layout messageDavid Neto1-3/+3
2018-06-26Block-decorated structs must list members in offset-orderDavid Neto1-67/+82
Additionally, implmentes code review feedback. Adds more detailed messages for Block and BufferBlock layout errors. Fixes #1638
2018-06-26Add validation for structs decorated as Block or BufferBlock.Ari Suonpaa4-4/+359
Fixes #937 Stop std140/430 validation when runtime array is encountered. Check for standard uniform/storage buffer layout instead of std140/430. Added validator command line switch to skip block layout checking. Validate structs decorated as Block/BufferBlock only when they are used as variable with storage class of uniform or push constant. Expose --relax-block-layout to command line. dneto0 modification: - Use integer arithmetic instead of floor.