[Mlir-commits] [mlir] [mlir][emitc] Add 'emitc.switch' op to the dialect (PR #102331)
Gil Rapaport
llvmlistbot at llvm.org
Fri Aug 9 09:33:06 PDT 2024
================
@@ -1302,5 +1304,195 @@ def EmitC_SubscriptOp : EmitC_Op<"subscript", []> {
let assemblyFormat = "$value `[` $indices `]` attr-dict `:` functional-type(operands, results)";
}
+def EmitC_SwitchOp : EmitC_Op<"switch", [RecursiveMemoryEffects,
+ SingleBlockImplicitTerminator<"emitc::YieldOp">,
+ DeclareOpInterfaceMethods<RegionBranchOpInterface,
+ ["getRegionInvocationBounds",
+ "getEntrySuccessorRegions"]>]> {
+ let summary = "Switch operation";
+ let description = [{
+ The `emitc.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 operand to a switch operation is a opaque or integral value.
+
+ The operation always has a "default" region and any number of case regions
+ denoted by integer constants. Control-flow transfers to the case region
+ whose constant value equals the value of the argument. If the argument does
+ not equal any of the case values, control-flow transfer to the "default"
+ region.
+
+ The operation does not return any value. Moreover, case regions and
+ default region must be explicitly terminated using the `emitc.yield` operation.
+
+ Example:
+
+ ```mlir
+ // Example for i32:
----------------
aniragil wrote:
Examples section seems overly detailed (cf. to examples in other EmitC ops):
- Selector's type doesn't imply significantly different semantics/output, so demonstrating a single type seems enough
- The `--declare-variables-at-top` flag affects other ops in a similar manner (and isn't demonstrated for them)
- Showing the op itself (without the function context) seems sufficient
- A single variable + call in the default section seems enough
Interested users can find more detailed examples in the dialect's tests.
https://github.com/llvm/llvm-project/pull/102331
More information about the Mlir-commits
mailing list