[flang-commits] [flang] [mlir][Interfaces] `LoopLikeOpInterface`: Add helper to get yielded values (PR #67305)

Felix Schneider via flang-commits flang-commits at lists.llvm.org
Mon Oct 9 23:22:31 PDT 2023


================
@@ -20,6 +20,19 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
     Contains helper functions to query properties and perform transformations
     of a loop. Operations that implement this interface will be considered by
     loop-invariant code motion.
+
+    Loop-carried variables can be exposed through this interface. There are
+    3 components to a loop-carried variable.
+    - The "region iter_arg" is the block argument of the entry block that
+      represents the loop-carried variable in each iteration.
+    - The "init value" is an operand of the loop op that serves as the initial
+      region iter_arg value for the first iteration (if any).
+    - The "yielded" value is the value that is forwarded from one iteration to
+      serve as the region iter_arg of the next iteration.
+
+    If one of the respective interface methods is implemented, so must the other
+    two. The interface verifier ensures that the number of types of the region
----------------
ubfx wrote:

> The renaming is needed because ops such as `scf::WhileOp` already have an auto-generated `getInits` function (that matches with the implementation that the interface expects).
> 
> This means we would have both `getInits` and `getLoopInits` etc. on most loop ops.

Ah, I see now why this is more complicated than just allowing the "non-sequentially-iterated loops" to implement `getInits()`.
Sorry - I didn't want to stall this PR, I'm fine with going ahead with it as it is now and trying to adapt the interface in the future to fit the different cases better. Maybe this is also a case where we are trying to square a circle by trying to cover both parallel-like and sequential-like loops perfectly with one interface - maybe this could be solved by interface inheritance in the future.

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


More information about the flang-commits mailing list