[Mlir-commits] [mlir] [mlir][emitc] Add 'emitc.while' and 'emitc.do' ops to the dialect (PR #143008)
Gil Rapaport
llvmlistbot at llvm.org
Wed Sep 24 06:41:30 PDT 2025
================
@@ -0,0 +1,238 @@
+// RUN: mlir-opt -allow-unregistered-dialect -convert-scf-to-emitc %s | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect -convert-to-emitc="filter-dialects=scf" %s | FileCheck %s
+
+emitc.func @payload_one_result(%arg: i32) -> i32 {
+ %result = add %arg, %arg : (i32, i32) -> i32
+ return %result : i32
+}
+
+func.func @one_result() -> i32 {
----------------
aniragil wrote:
Not sure I understand how the result variables capture the `scf.while` semantics. In this example for instance `%res` should have after the loop the last value computed for `%next` (i.e. `%VAL_8`), but `%VAL_12` is only assigned `%VAL_3` after the loop and `%VAL_3` is only assigned `%VAL_9` (in the `if` clause) for passing the iteration arg to the next iteration.
IIUC there is no direct relation between the iteration args and the results, and they may even have different arity, e.g.:
```mlir
func.func @different_number_of_vars() -> (i32, i32) {
%init = emitc.literal "1.0" : i32
%var = emitc.literal "7.0" : i32
%exit = emitc.literal "10.0" : i32
%res, %res2 = scf.while (%arg1 = %init) : (i32) -> (i32, i32) {
%sum = emitc.add %arg1, %var : (i32, i32) -> i32
%condition = emitc.cmp lt, %sum, %exit : (i32, i32) -> i1
%next = emitc.add %arg1, %arg1 : (i32, i32) -> i32
scf.condition(%condition) %next, %sum : i32, i32
} do {
^bb0(%arg2: i32, %arg3 : i32):
%next_arg1 = emitc.call @payload_one_result(%arg2) : (i32) -> i32
scf.yield %next_arg1 : i32
}
return %res, %res2 : i32, i32
}
```
The only requirements seem to be that
(a) the iteration args must match the `scf.yield` operands
(b) the results must match the `scf.condition` operands (minus the condition) and the `after` block arguments
Am I missing something?
https://github.com/llvm/llvm-project/pull/143008
More information about the Mlir-commits
mailing list