[Mlir-commits] [mlir] Refactor LoopFuseSiblingOp and support parallel fusion (PR #94391)
Oleksandr Alex Zinenko
llvmlistbot at llvm.org
Fri Jun 21 04:47:01 PDT 2024
================
@@ -618,6 +618,45 @@ void ForOp::getSuccessorRegions(RegionBranchPoint point,
SmallVector<Region *> ForallOp::getLoopRegions() { return {&getRegion()}; }
+FailureOr<LoopLikeOpInterface> ForallOp::replaceWithAdditionalYields(
+ RewriterBase &rewriter, ValueRange newInitOperands,
+ bool replaceInitOperandUsesInLoop,
+ const NewYieldValuesFn &newYieldValuesFn) {
+ // Create a new loop before the existing one, with the extra operands.
+ OpBuilder::InsertionGuard g(rewriter);
+ rewriter.setInsertionPoint(getOperation());
+ SmallVector<Value> inits(getOutputs());
+ inits.append(newInitOperands.begin(), newInitOperands.end());
+ scf::ForallOp newLoop = rewriter.create<scf::ForallOp>(
+ getLoc(), getMixedLowerBound(), getMixedUpperBound(), getMixedStep(),
+ inits, getMapping());
+
+ rewriter.eraseOp(newLoop.getTerminator());
+ // Move the loop body to the new op.
+ rewriter.mergeBlocks(getBody(), newLoop.getBody(),
+ newLoop.getBody()->getArguments().take_front(
+ getBody()->getNumArguments()));
+
+ if (replaceInitOperandUsesInLoop) {
+ // Replace all uses of `newInitOperands` with the corresponding basic block
+ // arguments.
+ for (auto it :
----------------
ftynse wrote:
Nit: `auto &&[first, second] : llvm::zip(...)` removes the need for `std::get`
https://github.com/llvm/llvm-project/pull/94391
More information about the Mlir-commits
mailing list