<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/75801>75801</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [SPIR-V] Structurize SPIR-V for graphics
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:SPIR-V
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            Keenuts
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Keenuts
      </td>
    </tr>
</table>

<pre>
    The current backend mostly supports OpenCL's SPIR-V.
For graphical SPIR-V, one crucial step needs to be added: the structurizer.

The spec defining what a structured control-flow means for SPIR-V is here:
https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_structured_control_flow

The current method we'd like to pursue would be relying on convergent intrinsics in the LLVM IR.
The frontend (only HLSL so far) will have to generate the correct convergent instructions around loops, and wave operations.

Once we have those operations, we believe the IR can be structured in 7 steps:
 - adding pre-headers to all the loops
 - split basic-blocks with different convergent operations. (Each basic block shall be linked to at most 1 convergent token)
 - merge back-edges for loops with multiple back edges.
 - identify convergence regions (regions sharing the same convergence token).
 - merge exit blocks for convergence region with multiple exits.
 
 At this point, we shall have a hierarchy of SESE regions, each associated with a convergence token.
 This should ensure we don't yoyo across convergence regions.
 
 Once those initial 5 steps done, we can add the SPIR-V instructions to determine merge/continue nodes.
 - Adding OpLoopMerge instructions to loop constructs.
 - Adding OpSelectionMerge to selection constructs

The last 2 steps will be slightly more complex, as we shall make sure no header share multiple OpSelectionMerge/OpLoopMerge, and no branch breaks out of multiple selection/loop constructs. But those are merely fixup steps once we have the initial 5 steps implemented.



</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsVU2T2jgQ_TXi0gVlBAQ4cJh8UJvaSWUrk8o1JaQ20iKrXWp5CPvrtyTbwJBc8IzdH69fv-5WzO4YEHdi9V5I-Tdi6BILKcXq40R1yVLcDS8nBzKX3XeLoLsYMSQ4KH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