Commit Graph

21 Commits

Author SHA1 Message Date
GregF
9de4e69856 Add AggressiveDCEPass
Create aggressive dead code elimination pass
This pass eliminates unused code from functions. In addition,
it detects and eliminates code which may have spurious uses but which do
not contribute to the output of the function. The most common cause of
such code sequences is summations in loops whose result is no longer used
due to dead code elimination. This optimization has additional compile
time cost over standard dead code elimination.

This pass only processes entry point functions. It also only processes
shaders with logical addressing. It currently will not process functions
with function calls. It currently only supports the GLSL.std.450 extended
instruction set. It currently does not support any extensions.

This pass will be made more effective by first running passes that remove
dead control flow and inlines function calls.

This pass can be especially useful after running Local Access Chain
Conversion, which tends to cause cycles of dead code to be left after
Store/Load elimination passes are completed. These cycles cannot be
eliminated with standard dead code elimination.

Additionally: This transform uses a whitelist of instructions that it
knows do have side effects, (a.k.a. combinators).  It assumes other
instructions have side effects: it will not remove them, and assumes
they have side effects via their ID operands.
2017-07-10 11:30:25 -04:00
GregF
cc8bad3a5b Add LocalMultiStoreElim pass
A SSA local variable load/store elimination pass.
For every entry point function, eliminate all loads and stores of function
scope variables only referenced with non-access-chain loads and stores.
Eliminate the variables as well.

The presence of access chain references and function calls can inhibit
the above optimization.

Only shader modules with logical addressing are currently processed.
Currently modules with any extensions enabled are not processed. This
is left for future work.

This pass is most effective if preceeded by Inlining and
LocalAccessChainConvert. LocalSingleStoreElim and LocalSingleBlockElim
will reduce the work that this pass has to do.
2017-07-07 17:54:21 -04:00
Greg Fischer
bba812f4e4 Inline: Inline early return function if no returns in loop. 2017-05-12 17:18:00 -04:00
Greg Fischer
04fcc66743 Add exhaustive function call inlining to spirv-opt
Inlining is done for all functions designated as entry points.

Add optional validation to test fixture method SinglePassRunAndCheck.
2017-03-29 18:02:40 -04:00
David Srbecky
b85997a1df Add various accessors needed to read and edit SPIRV code. 2017-03-29 14:38:57 +01:00
David Neto
9fc8658ef3 Relicense SPIRV-Tools under Apache 2.0
Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/383

Finalize v2016.4
2016-09-02 10:00:29 -04:00
David Neto
d7b6362ed7 Add Module::ComputeIdBound
When IDs change, something should use this utility method
and Module::SetIdBound before writing out the binary.
2016-08-26 16:27:12 -04:00
David Neto
97fc6aa3b8 ForEachInst optionally runs on attached debug line insts
Also:
- Add const forms of ForEachInst
- Rewrite Module::ToBinary in terms of ForEachInst
- Add Instruction::ToBinaryWithoutAttachedDebugInsts
- Delete the ToBinary method on Function, BasicBlock, and Instruction
  since it can now be implemented with ForEachInst in a less confusing
  way, e.g. without recursion.
- Preserve debug line instructions on OpFunctionEnd (and store that
  instruction as a unique-pointer, for regularity).
2016-08-25 11:43:22 -04:00
David Neto
ccabcc4673 Add opt::ir::Module::SetIdBound 2016-08-23 15:20:34 -04:00
Lei Zhang
097ff25ea7 Allow OpUndef appearing in the type and global variable section.
Also clean up API functions for adding instructions into the
type and global values section.
2016-08-15 10:44:14 -04:00
qining
d065593404 Add iterator getter interface for types_values_ 2016-08-12 15:10:51 -04:00
Lei Zhang
95dc16d1ec Add make_range() & make_const_range() for creating iterator ranges. 2016-08-12 10:34:47 -04:00
Lei Zhang
4b3247feba Avoid non-oneliner definition in class and add missing iterators. 2016-08-12 10:34:47 -04:00
Lei Zhang
645ee1d9e0 Create an iterator class for in-memory representation. 2016-08-11 18:35:12 -04:00
Lei Zhang
c562e231e3 Optimization: Add type manager.
Type manager will construct a map of types gradually from
instructions.
2016-08-10 12:53:17 -04:00
Lei Zhang
80c94a4fa8 Change the interfaces of in-memory representation to use pointers.
Previously we use vectors of objects and move semantics to handle
ownership. That approach has the flaw that inserting an object into
the middle of a vector, which may trigger a vector reallocation,
can invalidate some addresses taken from instructions.

Now the in-memory representation internally uses vector of unique
pointers to handle ownership. Since objects are explicitly heap-
allocated now, pointers to them won't be invalidated by vector
resizing anymore.
2016-08-10 12:11:33 -04:00
qining
51a2484b36 Dead constant elimination
A pass to remove dead constants, including both front-end constants and spec
constants.

This pass does not handle dead variables and types.
2016-08-08 17:17:15 -04:00
Lei Zhang
dcf28bf6ce Allow missing memory model instructions in modules. 2016-07-29 00:58:09 -04:00
Lei Zhang
abf8f6413c Promote ir namespace and create draft libspirv.{h|c}pp. 2016-06-28 14:52:34 -04:00
Lei Zhang
8590f9cc81 Add IrBuilder for constructing SPIR-V in-memory representation. 2016-06-27 16:57:42 -04:00
Lei Zhang
3df8f7cebd Add classes for representing SPIR-V language constructs in memory. 2016-06-24 20:54:06 -04:00