[mlir][scf] Add an IndexSwitchOp
authorJeff Niu <jeff@modular.com>
Sun, 16 Oct 2022 18:30:08 +0000 (11:30 -0700)
committerJeff Niu <jeff@modular.com>
Fri, 21 Oct 2022 16:21:10 +0000 (09:21 -0700)
commit07d8fe9391a1bda7bb5fdfd17a5b897df7a003f5
treeeac9ccbef07c5af7b55c13942ebb805f9871dcb2
parent0fbb261536a479c38a7bc26528b3f6984bfd4d84
[mlir][scf] Add an IndexSwitchOp

The `scf.index_switch` is a control-flow operation that branches to one of the
given regions based on the values of the argument and the cases. The
argument is always of type `index`.

Example:

```mlir
%0 = scf.index_switch %arg0 -> i32
case 2 {
  %1 = arith.constant 10 : i32
  scf.yield %1 : i32
}
case 5 {
  %2 = arith.constant 20 : i32
  scf.yield %2 : i32
}
default {
  %3 = arith.constant 30 : i32
  scf.yield %3 : i32
}
```

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D136003
mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
mlir/lib/Dialect/SCF/IR/SCF.cpp
mlir/test/Dialect/SCF/invalid.mlir
mlir/test/Dialect/SCF/ops.mlir