ModelBuilder was missing an api to easily generate yield-for-loops.
This diffs implements an interface allowing to write:
%2:2 = loop.for %i = %start to %end step %step iter_args(%arg0 = %init0, %arg1 = %init1) -> (f32, f32) { %sum = addf %arg0, %arg1 : f32 loop.yield %arg1, %sum : f32, f32 } %3 = addf %2#0, %2#1 : f32
as
auto results = LoopNestBuilder(&i, start, end, step, {&arg0, &arg1}, {init0, init1})([&] { auto sum = arg0 + arg1; loop_yield(ArrayRef<ValueHandle>{arg1, sum}); }); // Add the two values accumulated by the yield-for-loop: ValueHandle(results[0]) + ValueHandle(results[1]);
Nit: ValueRange instead of ArrayRef<Value> unless you have a strong reason to do otherwise.