Skip to content

Commit

Permalink
AIR BD canonicalization: must only fold affine.apply when the iv on…
Browse files Browse the repository at this point in the history
…ly has single use (Xilinx#675)

* Fixup a bug caused by 'hasOneUse' of iv not being enforced in affine.apply folding

* Improve dep tracing to take into consideration sync for + async affine.apply
  • Loading branch information
erwei-xilinx authored Jul 19, 2024
1 parent 0312707 commit 8727a53
Showing 1 changed file with 29 additions and 3 deletions.
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

0 comments on commit 8727a53

Please sign in to comment.