Skip to content

Added coredsl.switch - #4

Closed
PetrifiedPanda wants to merge 1 commit into
mainfrom
coredsl_switch
Closed

Added coredsl.switch#4
PetrifiedPanda wants to merge 1 commit into
mainfrom
coredsl_switch

Conversation

@PetrifiedPanda

Copy link
Copy Markdown
Collaborator

This is a modified version of scf.index_switch, which takes arbitrary integer arguments instead of the index type. This required creating the coredsl.yield operation, which is the yield statement for coredsl.switch.
Most of the code is almost the same as scf.index_switch, but there are some additional size checks for the integer arguments.

@7FM

7FM commented Apr 9, 2026

Copy link
Copy Markdown
Collaborator

I tend to be forgettable. I think we already had the discussion, but I can't recall the outcome. What is the reasoning to introduce our own switch operation instead of using https://mlir.llvm.org/docs/Dialects/ControlFlowDialect/#cfswitch-cfswitchop ? Especially since the implementation seems to add quite a lot of code.

@PetrifiedPanda

Copy link
Copy Markdown
Collaborator Author

The original problem I though cf.switch had was that it only seems to support values up to i32. I looked at this more closely later and this was a misunderstanding on my part.
I also later noticed that the default implementation of ControlFlowToSCFInterface also generates scf.index_switch operations, which would make longnail have to handle index types again. It may be possible to override this and emit coredsl.switch instead and thereby remove the index type completely.
I am not sure if handling cf.switch itself in longnail would also be an option, because then we could just emit cf.switch and handle that without needing coredsl.switch.
But if we want to convert to scf we would still end up with index types in the generated IR, which also means that switch statements with anything larger than the index type would not work as well.

@7FM

7FM commented Apr 10, 2026

Copy link
Copy Markdown
Collaborator

The conversion from cf to scf has to happen before lowering anyway, so I would assume there is a single cast to the index type for the scf.index_switch operation. If the transformation to a scf.If-else tree follows immediately, index types won't be practically visible.
Yes, the bitwidth limitation is not deniable (still better than no support and more than 64 bits will be a veery rare use case), but neither is the convenience of using existing operations and transformation :)
And I hope they will eventually add support for non-index types.

@7FM

7FM commented Apr 10, 2026

Copy link
Copy Markdown
Collaborator

If we ever decide to support loops with break and continue functionality, then cf dialect and ControlFlowToSCFInterface is the way to go anyway

@PetrifiedPanda

Copy link
Copy Markdown
Collaborator Author

Ok, then I'll work on the implementation using cf.switch. Am I right in assuming that this needs some changes in shortnail as well, such as allowing use of the cf dialect inside the coredsl dialect?

@7FM

7FM commented Apr 13, 2026

Copy link
Copy Markdown
Collaborator

Ok, then I'll work on the implementation using cf.switch. Am I right in assuming that this needs some changes in shortnail as well, such as allowing use of the cf dialect inside the coredsl dialect?

Guess we will see :'D

@PetrifiedPanda
PetrifiedPanda deleted the coredsl_switch branch June 3, 2026 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants