Branching off the discussion in Switch statement missing, I’d like to add switch
ops to the standard and structured control flow dialects.
std.switch
:
This would be unstructured control flow based on llvm.switch
. Given that branch weights are not present on other std branch operations, I do not think we should add them here at this time. In all other aspects, llvm.switch
seems like the right way to model this and I anticipate mostly copying over the code (including the custom switch cases printer/parser).
I believe it should be ok to add this new op to std, despite the ongoing effort to break std into multiple dialects because it is closely related to the existing br
and cond_br
ops and would move along with them to whatever new dialect we might create (say a “control flow” dialect for unstructured control flow).
scf.switch
:
This would be the structured version of switch, using regions, as in scf.if
and able to yield values, but taking no block arguments.
%x, %y = scf.switch %flag -> (f32, f32) {
%x_default = ...
%y_default = ...
%scf.yield %x_default, %y_default
} [
0: {
%x_0 = ...
%y_0 = ...
%scf.yield %x_0, %y_0
}
-1: {
%x_m1 = ...
%y_m1 = ...
%scf.yield %x_m1, %y_m1
}
]