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

AIRFuseAllocDealloc: Fixup op splicing issue between old and new air.hierarchy #864

Merged
merged 1 commit into from
Jan 18, 2025
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
Fixup op splicing between old and new air.hierarchy
erwei-xilinx committed Jan 18, 2025
commit adda952e3e09169cf4abcd536835fb694e0f29f2
29 changes: 17 additions & 12 deletions mlir/lib/Transform/AIRDependencyScheduleOpt.cpp
Original file line number Diff line number Diff line change
@@ -5728,15 +5728,6 @@ struct AIRFuseAllocDeallocToAIRHierarchy : public OpRewritePattern<OpTy> {

LogicalResult matchAndRewrite(OpTy op,
PatternRewriter &rewriter) const override {
// Skip if the op is not the inner-most loop of a perfect loop nest.
Region *opRegion = &op->getRegions().front();
Block *opBlock = &opRegion->front();
if (hasNImpureOps(opBlock, 1))
if (llvm::any_of(opBlock->without_terminator(), [](Operation &o) {
return isa_and_present<air::HierarchyInterface>(o);
}))
return failure();

llvm::SetVector<Value> usedMemrefsDefedAbove;
for (auto v : op->getOperands())
if (isa<MemRefType>(v.getType()))
@@ -5911,9 +5902,16 @@ struct AIRFuseAllocDeallocToAIRHierarchy : public OpRewritePattern<OpTy> {
auto newHerd = rewriter.create<OpTy>(
op->getLoc(), deps, op.getSizeOperands(), kernelOpers,
(bool)op.getAsyncToken(), op->getAttrs());
rewriter.inlineRegionBefore(op.getBody(), newHerd.getBody(),
newHerd.getBody().begin());
rewriter.eraseBlock(&newHerd.getBody().back());
for (unsigned i = 0; i < op.getNumDims(); i++) {
rewriter.replaceAllUsesWith(op.getIds()[i], newHerd.getIds()[i]);
rewriter.replaceAllUsesWith(op.getSize()[i], newHerd.getSize()[i]);
}
for (auto oper : kernelOpers)
rewriter.replaceAllUsesWith(op.getTiedKernelArgument(oper),
newHerd.getTiedKernelArgument(oper));
auto &bb = newHerd.getBody().front().getOperations();
auto &body = op.getBody().front().getOperations();
bb.splice(bb.begin(), body, body.begin(), --body.end());
rewriter.replaceOp(op, newHerd);
return success();
}
@@ -6146,5 +6144,12 @@ void applyAIRIsolateAsyncDmaLoopNestsPattern(Region *region) {
(void)AIRIsolateAsyncDmaLoopNestsImpl(region);
}

void populateAIRFuseAllocDeallocToAIRHierPatterns(RewritePatternSet &patterns) {
MLIRContext *ctx = patterns.getContext();
patterns.insert<AIRFuseAllocDeallocToAIRHierarchy<air::LaunchOp>,
AIRFuseAllocDeallocToAIRHierarchy<air::SegmentOp>,
AIRFuseAllocDeallocToAIRHierarchy<air::HerdOp>>(ctx);
}

} // namespace air
} // namespace xilinx