[Mlir-commits] [mlir] [mlir][emitc][cf] add 'cf.switch' support in CppEmitter (PR #101478)

Kirill Chibisov llvmlistbot at llvm.org
Fri Aug 2 03:39:57 PDT 2024


kchibisov wrote:

I'd add some background, since @EtoAndruwa works on my team.

The only reason we went for `cf.switch` is that emitc already has `cf.br` and `cf.cond_br`. In general, I'd favor an `emitc.switch` operation which always lowers without `goto` and uses simple `break`, so the `case` labels are not terminators and you can not _jump_ from them, so it'll look more like `emitc.if`, from what I understand in terms of child basic blocks.

In general, I'd prefer if `cf` dialect will lower to `emitc` dialect first and then be used by emitter, since it'll result in improved code gen and you won't need to account for `cf` when writing passes, since you can require lowering to `emitc` first.

>We can add a switch op, but it shouldn't be a terminator in my opinion. So we would be able to lower scf.index_switch to it, but we couldn't use it for cf.switch (as of now).

I wonder how the `scf.yield` will be lowered (though, I guess you can just specify that you can not `yield` result and say that each `case` should end with `emitc.break`, which yields nothing), though, you can likely define a variable just before the `switch` and assign to it, but all in all, `scf.index_swicth` like `emitc.switch` looks more appealing to us for already said `goto` stuff above, so +1 here.



https://github.com/llvm/llvm-project/pull/101478


More information about the Mlir-commits mailing list