Skip to content
This repository was archived by the owner on Oct 31, 2025. It is now read-only.
This repository was archived by the owner on Oct 31, 2025. It is now read-only.

Structured control flow #9

Closed
Closed

Description

@Jasper-Bekkers

MIR internally is pretty much completely unstructured which leads to some problems since in the flavour of SPIR-V that we're trying to support the control flow needs to be fully structured. The only flavor that supports unstructured controlflow is for OpenCL.

This requires potentially quite a bit of engineering to solve since the algorithms involved are relatively complex.

One avenue of exploration could be to see if we can shoehorn the Mesa3d controlflow restructurizer back into our compile chain:

Another option would be to implement either Stackifier or Relooper as part of spirv-opt that we run after the fact. We may already need to run spirv-opt to run mem2reg since we'll mostly be emitting OpLoad and OpStore instead of sticking to SSA proper.

Another option is one that @MaikKlein proposed:

There is I think another option that I haven't explored yet, and that is to remove some mir passes. Basically I think if you would remove most of the mir passes between HIR and MIR then the resulting cfg should be fairly easy to work with. I think most of the information will be lost during some of the optimization passes. Recomputing the control flow is fairly easy.

This option would leave the high-level controlflow constructs in tact without ever lowering them to branches/jumps which is a lot more robust then trying to reconstruct the structured controlflow from the jumps.

Some other projects have also run into similar issues:

Activity

  1. Jasper-Bekkers commented on Aug 18, 2020

    @Jasper-Bekkers
    ContributorAuthor

    My intuition is the pragmatic fast way to make progress on a few architectures is to drop structured control flow, but the long-term formal way to be portable across a diversity of architectures is to have a robust execution model, which at the moment wants structured control flow

    It may be worthwhile to experiment and see if the desktop gpus already support unstructured controlflow in their Vulkan drivers so we can potentially push this problem a little bit ahead of us while we work towards a minimally viable product.

  2. Jasper-Bekkers commented on Aug 18, 2020

    @Jasper-Bekkers
    ContributorAuthor

    Our hardware actually has IF, ELSE, ENDIF, and DO, BREAK, and CONT instructions.

    From Intel.

    waveops make absolutely no sense without structured control flow

    Another contribution.

  3. VZout commented on Aug 28, 2020

    @VZout
    Member

    Taking the Relooper approach seems like a good option for now. While not the most efficient, it would be a good start for me to get started with this kind of work and performance is likely not that important for the first prototype.
    Here is a tracking issue on my progress:

    #24

  4. repi commented on Oct 21, 2020

    @repi
    Contributor

    This old issue is partially resolved now right @VZout ?

  5. VZout commented on Oct 22, 2020

    @VZout
    Member

    There is a solution for the problem but not fully implemented yet. Currently only simple conditional branch's work.
    We can probably replace it with a tracking issue?

  6. repi commented on Oct 22, 2020

    @repi
    Contributor

    Ok np, could either create new one that tracks the progress support around this, or keep this one. up to you

  7. VZout commented on Oct 22, 2020

    @VZout
    Member

    Closing in favor of #97

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    t: enhancementA new feature or improvement to an existing one.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions