Commit Graph

19 Commits

Author SHA1 Message Date
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
Umar Arshad
8ea1268f84 Removed dead code/const_casts/lists 2016-08-09 18:09:38 -04:00
Umar Arshad
816f29805b Refactor Id -> Instruction 2016-08-09 15:50:03 -04:00
Umar Arshad
fd965c9e7e Remove unnecessary headers 2016-08-07 10:11:49 -04:00
Umar Arshad
ffa42994fd Remove needless copies. Delete copy constructor.
* Deletes the ValidationState_t copy constructor
* Removes needless copies of the copy constructor
2016-08-06 12:24:19 -04:00
David Neto
e712f826b6 Hide implementations of BasicBlock::dominates,postdominates 2016-08-05 16:55:21 -04:00
David Neto
605847f15b Track a construct by its entry block. 2016-08-05 16:05:44 -04:00
David Neto
b51b80980c Validator cfg fixes
- Find unreachable continue targets.  Look for back edges
  with a DFS traversal separate from the dominance traversals,
  where we count the OpLoopMerge from the header to the continue
  target as an edge in the graph.

- It's ok for a loop to have multiple back edges, provided
  they are all from the same block, and we call that the latch block.
  This may require a clarification/fix in the SPIR-V spec.

- Compute postdominance correctly for infinite loop:
  Bias *predecessor* traversal root finding so that you use
  a later block in the original list.  This ensures that
  for certain simple infinite loops in the CFG where neither
  block branches to a node without successors, that we'll
  compute the loop header as dominating the latch block, and the
  latch block as postdominating the loop header.
2016-08-05 15:15:37 -04:00
David Neto
3bf4dc102f Add BasicBlock methods: dominates postdominates 2016-08-05 15:14:18 -04:00
David Neto
bb4c0b1af6 Rename a variable so it's consistent with spec
In the spec "continue block" is a block with a branch
to the Continue Target.  It's not the Continue Target.
2016-08-05 15:12:47 -04:00
David Neto
c978b72477 Fix infinite loop in dominance calculation.
Ensure the dominance calculation visits all nodes in the CFG.
The successor list of the pseudo-entry node is augmented with
a single node in each cycle that otherwise would not be visited.
Similarly, the predecssors list of the pseduo-exit node is augmented
with the a single node in each cycle that otherwise would not
be visited.

Pulls DepthFirstSearch out so it's accessible outside of the dominator
calculation.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/279
2016-07-28 16:40:55 -04:00
Umar Arshad
66c94928a3 Refactor IDs definition and use tracking
* Creates an ID class which manages definition and use of IDs
* Moved tracking code from validate.cpp to validate_id.cpp
* Rename and combine SsaPass and ProcessIds into IdPass
* Remove module dependency in Function
2016-07-26 13:36:41 -04:00
Umar Arshad
886dd352d5 Fix several violations of the style guide 2016-06-27 10:45:46 -04:00
David Neto
5065227748 Use pseudo entry and pseudo exit blocks for dominance.
For dominance calculations we use an "augmented" CFG
where we always add a pseudo-entry node that is the predecessor
in the augmented CFG to any nodes that have no predecessors in the
regular CFG.  Similarly, we add a pseudo-exit node that is the
predecessor in the augmented CFG that is a successor to any
node that has no successors in the regular CFG.

Pseudo entry and exit blocks live in the Function object.

Fixes a subtle problem where we were implicitly creating
the block_details for the pseudo-exit node since it didn't
appear in the idoms map, and yet we referenced it.  In such a case the
contents of the block details could be garbage, or zero-initialized.
That sometimes caused incorrect calculation of immediate dominators
and post-dominators.  For example, on a debug build where the details
could be zero-initialized, the dominator of an unreachable block would
be given as the pseudo-exit node.  Bizarre.

Also, enforce the rule that you must have an OpFunctionEnd to close off
the last function.
2016-06-24 17:08:20 -04:00
Umar Arshad
f61db0bcc6 Validator structured flow checks: back-edge, constructs
Skip structured control flow chekcs for non-shader capability.

Fix infinite loop in dominator algorithm when there's an
unreachable block.
2016-06-22 11:51:19 -04:00
Lei Zhang
10dba91781 Use SPIR-V headers from the KhronosGroup/SPIRV-Headers repo. 2016-06-10 08:48:37 -04:00
Umar Arshad
e3dcaf5610 Refactor depth first traversal to be more generic
Refactor the way the post order vector is created. This new method
will allow for the extraction of backedges and create the post order
vector in one pass.
2016-06-10 06:39:42 -04:00
Umar Arshad
11437165d6 Fix diagnostic message for layout errors 2016-06-09 15:51:39 -04:00
Umar Arshad
90a4252aae Split validate_types file into multiple classes
Creates separate files for the ValidationState, Function and
BasicBlock classes.
2016-06-08 14:40:33 -04:00