scf.switch
← scf dialect
Multi-way branch over an index selector. Case keys are sorted unique i64 literals. The default region is mandatory and is selected when the selector does not equal any explicit case key. Every region must terminate with scf.yield matching the switch result tuple.
Operation contract
| Property |
Value |
| Semantic phase |
source structure |
| Traits |
ImplicitTerminator(scf.yield) |
| Interfaces |
RegionBranch |
Signature
| Kind |
Name |
Type |
Cardinality |
Description |
| Operand |
selector |
index |
required |
— |
| Result |
results |
any |
variadic |
— |
| Attribute |
case_keys |
i64_array |
required |
Sorted unique selector values for explicit switch cases. |
| Region |
default_region |
region |
required |
Executed when no explicit case key matches. Terminated by scf.yield. (single block, terminator scf.yield.) |
| Region |
case_regions |
region |
variadic |
Case regions in the same order as case_keys. Terminated by scf.yield. (single block, terminator scf.yield.) |
Examples
scf.switch %selector {
case 0 {
scf.yield
}
default {
scf.yield
}
}
%result = scf.switch %selector -> (f32) {
case 0 {
scf.yield %a : f32
}
case 1 {
scf.yield %b : f32
}
default {
scf.yield %fallback : f32
}
}