Skip to content

Commit

Permalink
If all users of an air.wait_all are async ops, then fold it to all it…
Browse files Browse the repository at this point in the history
…s users
  • Loading branch information
erwei-xilinx committed Dec 31, 2024
1 parent a2e4acc commit 1eba001
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions mlir/lib/Dialect/AIR/IR/AIRDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,30 @@ static LogicalResult FoldWaitAll(WaitAllOp op, PatternRewriter &rewriter) {
return success();
}

// If all of async wait_all's users have AsyncOpInterface, fold it into its
// users
if (op.getResults().size() == 1 &&
llvm::all_of(op.getResults().front().getUsers(), [](Operation *user) {
return isa_and_present<air::AsyncOpInterface>(user);
})) {
SmallVector<Operation *> users;
for (auto user : op.getResults().front().getUsers()) {
users.push_back(user);
}
for (auto user : users) {
air::AsyncOpInterface asyncUser =
dyn_cast_if_present<air::AsyncOpInterface>(user);
for (int i = asyncUser.getAsyncDependencies().size() - 1; i >= 0; i--) {
if (asyncUser.getAsyncDependencies()[i] == op.getResults().front())
asyncUser.eraseAsyncDependency(i);
}
for (auto dep : op.getAsyncDependencies())
asyncUser.addAsyncDependency(dep);
}
rewriter.eraseOp(op);
return success();
}

return failure();
}

Expand Down

0 comments on commit 1eba001

Please sign in to comment.