summaryrefslogtreecommitdiff
path: root/tools
AgeCommit message (Collapse)AuthorFilesLines
2018-07-31Transform to combine consecutive access chainsAlan Baker1-0/+3
* Combines OpAccessChain, OpInBoundsAccessChain, OpPtrAccessChain and OpInBoundsPtrAccessChain * New folding rule to fold add with 0 for integers * Converts to a bitcast if the result type does not match the operand type V
2018-07-31Fix bug determining next argAlan Baker1-1/+1
2018-07-27Add API to create passes out of a list of command-line flags.Diego Novillo1-218/+84
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-11Add option to skip verifying block layoutLei Zhang1-1/+5
We need this to avoid emitting errors on DirectX layout rules.
2018-07-10Reopen stdin for binary as neededDavid Neto1-3/+5
Fixes #1688
2018-07-07Change libspirv to spvtools namespace (#1678)dan sinclair4-14/+14
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 sinclair2-2/+2
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 sinclair6-31/+39
This CL moves the code in the comp/ directories into the comp namespace.
2018-06-26Add validation for structs decorated as Block or BufferBlock.Ari Suonpaa1-1/+4
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.
2018-06-21Add a WIP WebGPU environment. It disallows OpUndefCorentin Wallez1-4/+5
Add SPV_ENV_WEBGPU_0 for work-in-progress WebGPU. val: Disallow OpUndef in WebGPU env Silence unused variable warnings when !defined(SPIRV_EFFCE) Limit visibility of validate_instruction.cpp's symbols Only InstructionPass needs to be visible so all other functions are put in an anonymous namespace inside the libspirv namespace.
2018-06-19[val] Add extra context to error messages. (#1600)dan sinclair2-4/+8
[val] Add extra context to error messages. This CL extends the error messages produced by the validator to output the disassembly of the errored line. The validation_id messages have also been updated to print the line number of the error instead of the word number. Note, the error number is from the start of the SPIR-V, it does not include any headers printed in the disassembled code. Fixes #670, #1581
2018-06-01Delete the insert-extract-elim pass.Steven Perron1-3/+3
Replaces anything that creates an insert-extract-elim pass and create a simplifiation pass instead. Then delete the implementation of the pass. Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/1570.
2018-05-18Remove the limit on struct size in SROA.Steven Perron1-2/+7
Removes the limit on scalar replacement for the lagalization passes. This is done by adding an option to the pass (and command line option) to set the limit on maximum size of the composite that scalar replacement is willing to divide. Fixes #1494.
2018-05-16Fix getting operand without checking opcode.Steven Perron1-3/+6
Fixes https://github.com/KhronosGhttps://github.com/KhronosGroup/SPIRV-Tools/issues/1559roup/SPIRV-Tools/issues/1559. There is an load of an operand of an instruction that was suppose to be only for the OpCompositeExtract case. However, an error caused it to be loaded for every opcode, even those that do not have an operand in that position. We fix up that bug, and a couple other things noticed that the same time.
2018-05-14Add pass to fold a load feeding an extract.Steven Perron1-0/+2
We have already disabled common uniform elimination because it created sequences of loads an entire uniform object, then we extract just a single element. This caused problems in some drivers, and is just generally slow because it loads more memory than needed. However, there are other way to get into this situation, so I've added a pass that looks specifically for this pattern and removes it when only a portion of the load is used. Fixes #1547.
2018-05-01Fix build.Diego Novillo1-0/+4
2018-05-01Add a loop fusion pass.Toomas Remmelg1-0/+24
This pass will look for adjacent loops that are compatible and legal to be fused. Loops are compatible if: - they both have one induction variable - they have the same upper and lower bounds - same initial value - same condition - they have the same update step - they are adjacent - there are no break/continue in either of them Fusion is legal if: - fused loops do not have any dependencies with dependence distance greater than 0 that did not exist in the original loops. - there are no function calls in the loops (could have side-effects) - there are no barriers in the loops It will fuse all such loops as long as the number of registers used for the fused loop stays under the threshold defined by max_registers_per_loop.
2018-05-01Support loop fission.Stephen McGroarty1-0/+23
Adds support for spliting loops whose register pressure exceeds a user provided level. This pass will split a loop into two or more loops given that the loop is a top level loop and that spliting the loop is legal. Control flow is left intact for dead code elimination to remove. This pass is enabled with the --loop-fission flag to spirv-opt.
2018-04-23Vector DCE (#1512)Steven Perron1-0/+6
Introduce a pass that does a DCE type analysis for vector elements instead of the whole vector as a single element. It will then rewrite instructions that are not used with something else. For example, an instruction whose value are not used, even though it is referenced, is replaced with an OpUndef.
2018-04-12Fixes #1471. Adds missing environments to spriv-val helpAlan Baker1-2/+3
* spirv-val: Added environments referenced in --version, but not mentioned in --help
2018-04-11Add a loop peeling pass.Victor Lomuller1-0/+30
For each loop in a function, the pass walks the loops from inner to outer most loop and tries to peel loop for which a certain amount of iteration can be done before or after the loop. To limit code growth, peeling will not happen if the growth in code size goes above a configurable threshold.
2018-03-26Copy propagate arraysSteven Perron1-0/+6
The sprir-v generated from HLSL code contain many copyies of very large arrays. Not only are these time consumming, but they also cause problems for drivers because they require too much space. To work around this, we will implement an array copy propagation. Note that we will not implement a complete array data flow analysis in order to implement this. We will be looking for very simple cases: 1) The source must never be stored to. 2) The target must be stored to exactly once. 3) The store to the target must be a store to the entire array, and be a copy of the entire source. 4) All loads of the target must be dominated by the store. The hard part is keeping all of the types correct. We do not want to have to do too large a search to update everything, which may not be possible, do we give up if we see any instruction that might be hard to update. Also in types.h, the element decorations are not stored in an std::map. This change was done so the hashing algorithm for a Struct is consistent. With the std::unordered_map, the traversal order was non-deterministic leading to the same type getting hashed to different values. See |Struct::GetExtraHashWords|. Contributes to #1416.
2018-03-22Fixes compile errors generated with -WpedanticEleni Maria Stea1-1/+1
This patch fixes the compile errors generated when the options SPIRV_WARN_EVERYTHING and SPIRV_WERROR (that force -Wpedantic) are set to cmake.
2018-03-20Add --time-report to spirv-optJaebaek Seo1-0/+9
This patch adds a new option --time-report to spirv-opt. For each pass executed by spirv-opt, the flag prints resource utilization for the pass (CPU time, wall time, RSS and page faults) This fixes issue #1378
2018-03-20SSA rewrite pass.Diego Novillo1-4/+6
This pass replaces the load/store elimination passes. It implements the SSA re-writing algorithm proposed in Simple and Efficient Construction of Static Single Assignment Form. Braun M., Buchwald S., Hack S., Leißa R., Mallon C., Zwinkau A. (2013) In: Jhala R., De Bosschere K. (eds) Compiler Construction. CC 2013. Lecture Notes in Computer Science, vol 7791. Springer, Berlin, Heidelberg https://link.springer.com/chapter/10.1007/978-3-642-37051-9_6 In contrast to common eager algorithms based on dominance and dominance frontier information, this algorithm works backwards from load operations. When a target variable is loaded, it queries the variable's reaching definition. If the reaching definition is unknown at the current location, it searches backwards in the CFG, inserting Phi instructions at join points in the CFG along the way until it finds the desired store instruction. The algorithm avoids repeated lookups using memoization. For reducible CFGs, which are a superset of the structured CFGs in SPIRV, this algorithm is proven to produce minimal SSA. That is, it inserts the minimal number of Phi instructions required to ensure the SSA property, but some Phi instructions may be dead (https://en.wikipedia.org/wiki/Static_single_assignment_form).
2018-03-19Change merge return pass to handle structured cfg.Steven Perron1-4/+13
We are seeing shaders that have multiple returns in a functions. These functions must get inlined for legalization purposes; however, the inliner does not know how to inline functions that have multiple returns. The solution we will go with it to improve the merge return pass to handle structured control flow. Note that the merge return pass will assume the cfg has been cleanedup by dead branch elimination. Fixes #857.
2018-03-15Add --strip-reflect passDavid Neto1-0/+5
Strips reflection info. This is limited to decorations and decoration instructions related to the SPV_GOOGLE_hlsl_functionality1 extension. It will remove the OpExtension for SPV_GOOGLE_hlsl_functionality1. It will also remove the OpExtension for SPV_GOOGLE_decorate_string if there are no further remaining uses of OpDecorateStringGOOGLE. Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/1398
2018-03-06Support SPIR-V 1.3 and Vulkan 1.1David Neto4-12/+18
The default target is SPIR-V 1.3. For example, spirv-as will generate a SPIR-V 1.3 binary by default. Use command line option "--target-env spv1.0" if you want to make a SPIR-V 1.0 binary or validate against SPIR-V 1.0 rules. Example: # Generate a SPIR-V 1.0 binary instead of SPIR-V 1.3 spirv-as --target-env spv1.0 a.spvasm -o a.spv spirv-as --target-env vulkan1.0 a.spvasm -o a.spv # Validate as SPIR-V 1.0. spirv-val --target-env spv1.0 a.spv # Validate as Vulkan 1.0 spirv-val --target-env vulkan1.0 a.spv
2018-02-27Consistently include latest spirv.h header file.David Neto1-1/+1
Use indirection through latest_version_spirv.h Also, when generating enum tables, use the unified1 JSON grammar since it now has FragmentFullyCoveredEXT but the other JSON grammars don't. They are starting to fall behind.
2018-02-27linker: Allow modules to be partially linkedPierre Moreau1-7/+10
Fixes: https://github.com/KhronosGroup/SPIRV-Tools/issues/1144
2018-02-27tools/linker: Allow setting --verify-ids on the command linePierre Moreau1-0/+3
2018-02-27Add loop unswitch pass.Victor Lomuller1-0/+6
It moves all conditional branching and switch whose conditions are loop invariant and uniform. Before performing the loop unswitch we check that the loop does not contain any instruction that would prevent it (barriers, group instructions etc.).
2018-02-27Unroller support for multiple induction variablesStephen McGroarty1-1/+28
Support for multiple induction variables within a loop and support for loop condition operands <= and >=.
2018-02-14Initial support for loop unrolling.Stephen McGroarty1-0/+2
This patch adds initial support for loop unrolling in the form of a series of utility classes which perform the unrolling. The pass can be run with the command spirv-opt --loop-unroll. This will unroll loops within the module which have the unroll hint set. The unroller imposes a number of requirements on the loops it can unroll. These are documented in the comments for the LoopUtils::CanPerformUnroll method in loop_utils.h. Some of the restrictions will be lifted in future patches.
2018-02-08Loop invariant code motion initial implementationAlexander Johnston1-0/+2
2018-02-07Make use of the instruction folder.Steven Perron1-0/+5
Implementation of the simplification pass. - Create pass that calls the instruction folder on each instruction and propagate instructions that fold to a copy. This will do copy propagation as well. - Did not use the propagator engine because I want to modify the instruction as we go along. - Change folding to not allocate new instructions, but make changes in place. This change had a big impact on compile time. - Add simplification pass to the legalization passes in place of insert-extract elimination. - Added test cases for new folding rules. - Added tests for the simplification pass - Added a method to the CFG to apply a function to the basic blocks in reverse post order. Contributes to #1164.
2018-02-01Add pass to reaplce invalid opcodesSteven Perron1-0/+6
Creates a pass that will remove instructions that are invalid for the current shader stage. For the instruction to be considered for replacement 1) The opcode must be valid for a shader modules. 2) The opcode must be invalid for the current shader stage. 3) All entry points to the module must be for the same shader stage. 4) The function containing the instruction must be reachable from an entry point. Fixes #1247.
2018-01-30InsertExtractElim: Split out DeadInsertElim as separate passGregF1-0/+6
2018-01-25Initial implementation of if conversionAlan Baker1-0/+4
* Handles simple cases only * Identifies phis in blocks with two predecessors and attempts to convert the phi to an select * does not perform code motion currently so the converted values must dominate the join point (e.g. can't be defined in the branches) * limited for now to two predecessors, but can be extended to handle more cases * Adding if conversion to -O and -Os
2018-01-18Create a pass to work around a driver bug related to OpUnreachable.Steven Perron1-0/+6
We have come across a driver bug where and OpUnreachable inside a loop is causing the shader to go into an infinite loop. This commit will try to avoid this bug by turning OpUnreachable instructions that are contained in a loop into branches to the loop merge block. This is not added to "-O" and "-Os" because it should only be used if the driver being targeted has this problem. Fixes #1209.
2018-01-18spirv-dis: Add --color option to force color disassemblyDavid Neto1-9/+23
Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/1170
2018-01-08Allow relaxing validation of pointers in logical addressing modeLei Zhang1-0/+4
In HLSL structured buffer legalization, pointer to pointer types are emitted to indicate a structured buffer variable should be treated as an alias of some other variable. We need an option to relax the check of pointer types in logical addressing mode to catch other validation errors.
2018-01-05Linker code cleanupsPierre Moreau1-6/+9
Turn `Linker::Link()` into free functions As very little information was kept in the Linker class, we can get rid of the whole class and have the `Link()` as free functions instead; the environment target as well as the consumer are passed along through an `spv_context` object. The resulting linked_binary is passed as a pointer rather than a reference to follow the Google C++ Style guidelines. Addresses remaining comments from https://github.com/KhronosGroup/SPIRV-Tools/pull/693 about the SPIR-V linker. Fix variable naming in the linker Some of the variables were using mixed case, which did not follow the Google C++ Style guidelines. Linker: Use EXPECT_EQ when possible and update some test * Replace occurrences of ASSERT_EQ by EXPECT_EQ when possible; * Reformulated some of the error messages; * Added the symbol name in the error message when there is a type or decoration mismatch between the imported and exported declarations. Opt: List all duplicates removed by RemoveDuplicatePass in the header Opt: Make the const version of GetLabelInst() return a pointer For consistency with the non-const version, as well as other similar functions. Opt: Rename function_end to EndInst() As pointed out by dneto0 the previous name was quite confusing and could be mistaken with a function returning an end iterator. Also change the return type of the const version to a pointer rather than a reference, for consistency. Opt: Add performance comment to RemoveDuplicateTypes and decorations This comment was requested during the review of https://github.com/KhronosGroup/SPIRV-Tools/pull/693. Opt: Add comments and fix variable naming in RemoveDuplicatePass * Add missing comments to private functions; * Rename variables that were using mixed case; * Add TODO for moving AreTypesEqual out. Linker: Remove commented out code and add TODOs Linker: Merged together strings that were too much splitted Implement a C++ RAII wrapper around spv_context
2018-01-04Add --print-all optimizer optionDavid Neto1-0/+5
Adds optimizer API to write disassembly to a given output stream before each pass, and after the last pass. Adds spirv-opt --print-all option to write disassembly to stderr before each pass, and after the last pass.
2017-12-21Implement SSA CCP (SSA Conditional Constant Propagation).Diego Novillo1-0/+8
This implements the conditional constant propagation pass proposed in Constant propagation with conditional branches, Wegman and Zadeck, ACM TOPLAS 13(2):181-210. The main logic resides in CCPPass::VisitInstruction. Instruction that may produce a constant value are evaluated with the constant folder. If they produce a new constant, the instruction is considered interesting. Otherwise, it's considered varying (for unfoldable instructions) or just not interesting (when not enough operands have a constant value). The other main piece of logic is in CCPPass::VisitBranch. This evaluates the selector of the branch. When it's found to be a known value, it computes the destination basic block and sets it. This tells the propagator which branches to follow. The patch required extensions to the constant manager as well. Instead of hashing the Constant pointers, this patch changes the constant pool to hash the contents of the Constant. This allows the lookups to be done using the actual values of the Constant, preventing duplicate definitions.
2017-12-21Fixing bugs in type manager memory managementAlan Baker1-0/+5
* changed the way duplicate types are removed to stop copying instructions * Reworked RemoveDuplicatesPass::AreTypesSame to use type manager and type equality * Reworked TypeManager memory management to store a pool of unique pointers of types * removed unique pointers from id map * fixed instances where free'd memory could be accessed
2017-12-20Update the legalization passes.Steven Perron1-2/+19
Changes the set of optimizations done for legalization. While doing this, I added documentation to explain why we want each optimization. A new option "--legalize-hlsl" is added so the legalization passes can be easily run from the command line. The legalize option implies skip-validation.
2017-12-19Convert private variables to function scope.Steven Perron1-0/+5
When a private variable is used in a single function, it can be converted to a function scope variable in that function. This adds a pass that does that. The pass can be enabled using the option `--private-to-local`. This transformation allows other transformations to act on these variables. Also moved `FindPointerToType` from the inline class to the type manager.
2017-12-11Add scalar replacementAlan Baker1-2/+11
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-08Add option to spirv-opt to skip the validator.Steven Perron1-22/+32
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.