Skip to content
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

AIR BD canonicalization: must only fold affine.apply when the iv only has single use #675

Merged
Merged
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
32 changes: 29 additions & 3 deletions mlir/lib/Transform/AIRDependencyScheduleOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1685,6 +1685,8 @@ struct CanonicalizeAffineApplyOnLoopInductionVar
return failure();
if (!ivArg.getOwner())
return failure();
if (!val.hasOneUse())
return failure();
if (apply.getResult().use_empty())
return failure();
if (auto exec_apply = dyn_cast<air::ExecuteOp>(apply->getParentOp()))
Expand Down Expand Up @@ -1713,7 +1715,15 @@ struct CanonicalizeAffineApplyOnLoopInductionVar
if (auto exec = dyn_cast<air::ExecuteOp>(apply->getParentOp())) {
rewriter.setInsertionPoint(exec);
exec.getResult(1).replaceAllUsesWith(sfo.getInductionVar());
exec.getAsyncToken().replaceAllUsesWith(sfo.getRegionIterArgs()[0]);
if (sfo.getNumRegionIterArgs())
exec.getAsyncToken().replaceAllUsesWith(sfo.getRegionIterArgs()[0]);
else if (exec.getAsyncDependencies().size() == 1)
exec.getAsyncToken().replaceAllUsesWith(
exec.getAsyncDependencies()[0]);
else {
exec->emitOpError("failed to reconstruct dependency after its erase");
return failure();
}
rewriter.eraseOp(exec);
} else {
rewriter.setInsertionPoint(apply);
Expand Down Expand Up @@ -1810,7 +1820,15 @@ struct CanonicalizeArithMuliOpOnLoopInductionVar
if (auto exec = dyn_cast<air::ExecuteOp>(op->getParentOp())) {
rewriter.setInsertionPoint(exec);
exec.getResult(1).replaceAllUsesWith(sfo.getInductionVar());
exec.getAsyncToken().replaceAllUsesWith(sfo.getRegionIterArgs()[0]);
if (sfo.getNumRegionIterArgs())
exec.getAsyncToken().replaceAllUsesWith(sfo.getRegionIterArgs()[0]);
else if (exec.getAsyncDependencies().size() == 1)
exec.getAsyncToken().replaceAllUsesWith(
exec.getAsyncDependencies()[0]);
else {
exec->emitOpError("failed to reconstruct dependency after its erase");
return failure();
}
rewriter.eraseOp(exec);
} else {
rewriter.setInsertionPoint(op);
Expand Down Expand Up @@ -1899,7 +1917,15 @@ struct CanonicalizeArithAddiOpOnLoopInductionVar
if (auto exec = dyn_cast<air::ExecuteOp>(op->getParentOp())) {
rewriter.setInsertionPoint(exec);
exec.getResult(1).replaceAllUsesWith(sfo.getInductionVar());
exec.getAsyncToken().replaceAllUsesWith(sfo.getRegionIterArgs()[0]);
if (sfo.getNumRegionIterArgs())
exec.getAsyncToken().replaceAllUsesWith(sfo.getRegionIterArgs()[0]);
else if (exec.getAsyncDependencies().size() == 1)
exec.getAsyncToken().replaceAllUsesWith(
exec.getAsyncDependencies()[0]);
else {
exec->emitOpError("failed to reconstruct dependency after its erase");
return failure();
}
rewriter.eraseOp(exec);
} else {
rewriter.setInsertionPoint(op);
Expand Down
Loading