Generate correctly structured do-while loops.
authorDavid Neto <dneto@google.com>
Wed, 15 Jul 2015 20:21:26 +0000 (16:21 -0400)
committerDavid Neto <dneto@google.com>
Fri, 17 Jul 2015 21:51:51 +0000 (17:51 -0400)
commitc22f37cfb42a5a26f87ba60cc7ce3262f322447d
tree6ca25fc071fa9581b173866e18825e4880a0e964
parent51b31b57855d4657d80f6badbec455786b212725
Generate correctly structured do-while loops.

The loop test is always emitted before the loop body.

For do-while loops, use a phi node to track whether we're
on the first loop iteration, and only check the loop test
on the second and subsequent iterations.

For do-while loops, the loop test branch no longer occurs
at the top of the loop, so it must get its own selection
merge instruction.

A block can't be the target of more than one merge instruction.
So when the loop test executes after the body (as in do-while in GLSL)
we need to introduce a dummy block to be the target of the selection
merge just before the loop test conditional branch.

The other arm of the branch exits the loop and hence is the
"break block" exception in the structured control flow rules.
SPIRV/GlslangToSpv.cpp
SPIRV/SpvBuilder.cpp
SPIRV/SpvBuilder.h
Test/baseResults/spv.do-simple.vert.out
Test/baseResults/spv.do-while-continue-break.vert.out
Test/baseResults/spv.doWhileLoop.frag.out
Test/baseResults/spv.loops.frag.out
Test/baseResults/spv.loopsArtificial.frag.out