Skip to content

[MLIR] revise IfLowering of LoopToStandard Pass to support IfOp with … #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions mlir/lib/Conversion/LoopToStandard/LoopToStandard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,10 @@ LogicalResult IfLowering::matchAndRewrite(IfOp ifOp,
// place it before the continuation block, and branch to it.
auto &thenRegion = ifOp.thenRegion();
auto *thenBlock = &thenRegion.front();
rewriter.eraseOp(thenRegion.back().getTerminator());
auto thenTerminator = thenRegion.back().getTerminator();
continueBlock->addArguments(thenTerminator->getOperandTypes());
auto thenYieldValues = thenTerminator->getOperands();
rewriter.eraseOp(thenTerminator);
rewriter.setInsertionPointToEnd(&thenRegion.back());
rewriter.create<BranchOp>(loc, continueBlock);
rewriter.inlineRegionBefore(thenRegion, continueBlock);
Expand All @@ -256,9 +259,14 @@ LogicalResult IfLowering::matchAndRewrite(IfOp ifOp,
auto &elseRegion = ifOp.elseRegion();
if (!elseRegion.empty()) {
elseBlock = &elseRegion.front();
rewriter.eraseOp(elseRegion.back().getTerminator());
auto elseTerminator = elseRegion.back().getTerminator();
assert(elseTerminator->getOperandTypes() ==
thenTerminator->getOperandTypes() &&
"Yield values from thenBlock and elseBlock mismatch");
auto elseYieldValues = elseTerminator->getOperands();
rewriter.eraseOp(elseTerminator);
rewriter.setInsertionPointToEnd(&elseRegion.back());
rewriter.create<BranchOp>(loc, continueBlock);
rewriter.create<BranchOp>(loc, continueBlock, elseYieldValues);
rewriter.inlineRegionBefore(elseRegion, continueBlock);
}

Expand Down