[RFC] Adding operands and results to loop.for

I’m generally supportive of the RFC. It has indeed been discussed several times, with the early versions dating back to the introduction of the Loop dialect. We just haven’t had a good enough reason to push through the implementation (loops were a common lowering target for Affine and Linalg, neither of which needed it at that point).

My suggestion for syntax would be something like

%42 = ...
%43 = ...
%res:2 = loop.for %iv = %lb to %ub step %step
         args(%arg1 = %42 : tensor<*xf32>, %arg2 = %43 : tensor<*xf32>) {
  // %arg1 and %arg2 are available here
  %57 = ...
  loop.yield %57, %57 : tensor<*xf32>, tensor<*xf32>
}

One note: forwarding values into a region-encolsing op seems to be a common pattern, so I would encourage you to come up with a common syntax that is general enough to be reused for different operations, e.g. (the former version of isolated-from-above) gpu.launch and the proposed inlined_call.

Similarly to the loop.if extension, I would suggest removing loop.terminator and replacing it with loop.yield in all cases. We can also require loop.yield to always appear in the custom syntax, even if when has no operands, for consistency. (Practically, I don’t think we have support for conditionally implicit terminators).

I think it is reasonable to have types listed before the region rather than in the training position of the enclosing. These types are necessary to construct the entry block of the region.

Nit on the value naming: %iv will become %arg0 because that’s how the printer names block arguments. So the following loop-carried arguments are %arg1, %arg2 and so on. Using %arg0 outside the region creates confusion. Having the “assignment” form %nameWithinRegion = %nameOutsideRegion : type looks the right approach to me, and it was discussed on the GPU dialect syntax at the time. I think it also addresses @mehdi_amini’s concern of having the arguments named. Practically, it is necessary to list the SSA values and their types before the region start if we want to omit the header (^bb0) for the entry block.