[Mlir-commits] [mlir] [mlir][Transform] Extend transform.foreach to take multiple arguments (PR #93705)
Oleksandr Alex Zinenko
llvmlistbot at llvm.org
Thu May 30 00:59:48 PDT 2024
================
@@ -1409,28 +1456,44 @@ transform::ForeachOp::apply(transform::TransformRewriter &rewriter,
return result;
}
- // Append yielded payload ops to result list (if any).
- for (unsigned i = 0; i < getNumResults(); ++i) {
- auto yieldedOps = state.getPayloadOps(getYieldOp().getOperand(i));
- resultOps[i].append(yieldedOps.begin(), yieldedOps.end());
- }
+ // Append yielded payloads to results.
+ auto yieldOperands = getYieldOp().getOperands();
+ for (auto &&[result, yieldOperand, resTuple] :
+ llvm::zip_equal(getResults(), yieldOperands, zippedResults))
+ // NB: each iteration we add any number of ops/vals/params to an opresult.
+ if (isa<TransformHandleTypeInterface>(result.getType()))
+ llvm::append_range(resTuple, state.getPayloadOps(yieldOperand));
+ else if (isa<TransformValueHandleTypeInterface>(result.getType()))
+ llvm::append_range(resTuple, state.getPayloadValues(yieldOperand));
+ else if (isa<TransformParamTypeInterface>(result.getType()))
+ llvm::append_range(resTuple, state.getParams(yieldOperand));
----------------
ftynse wrote:
Not necessarily for this commit, but I can't help wondering if we should provide a `state.getMappedValues()` that returns an iterator range and hides this common dispatch. This may not be trivial since individual `get*` functions return different types, some of which are already deduced iterator types, but may be worth a try.
https://github.com/llvm/llvm-project/pull/93705
More information about the Mlir-commits
mailing list