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

Handle tcp.bind_symbolic_shape ops in fusion algorithm #82

Merged
Merged
Changes from 1 commit
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
17 changes: 17 additions & 0 deletions lib/Dialect/Transforms/FusionPatterns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,15 @@ GenericBottomUpFuser::matchAndRewrite(Operation *op,
Region *usesParentRegion = nullptr;
SmallVector<Operation *> uses;
llvm::DenseSet<Operation *> usesSet;
llvm::DenseSet<tcp::BindSymbolicShapeOp> bindShapeUses;

LLVM_DEBUG(llvm::dbgs() << "Processing op: " << *op << "\n");
for (auto &use : op->getUses()) {
if (auto bindShapeOp = dyn_cast<tcp::BindSymbolicShapeOp>(use.getOwner())) {
bindShapeUses.insert(bindShapeOp);
continue;
}

auto parentRegion = use.getOwner()->getParentRegion();
if (usesParentRegion && usesParentRegion != parentRegion)
return failure();
Expand All @@ -58,6 +65,10 @@ GenericBottomUpFuser::matchAndRewrite(Operation *op,
uses.push_back(use.getOwner());
}

// All its uses are tcp.bind_symbolic_shpae ops.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: typo

if (uses.empty())
return failure();

// Sorting by dominance ensures that the first element of this vector is
// the first use of the def. Used below when we want to move the op into
// an existing group.
Expand Down Expand Up @@ -104,6 +115,9 @@ GenericBottomUpFuser::matchAndRewrite(Operation *op,
use->moveBefore(yieldOp);
}
op->moveBefore(*uses.begin());
for (auto bindShapeOp : bindShapeUses) {
bindShapeOp->moveBefore(yieldOp);
}
}

// We then replace all uses of the uses which lie outside the group
Expand Down Expand Up @@ -157,6 +171,9 @@ GenericBottomUpFuser::matchAndRewrite(Operation *op,
// reordered.
auto &firstOp = *usesParentRegion->getOps().begin();
op->moveBefore(&firstOp);
for (auto bindShapeOp : bindShapeUses) {
bindShapeOp->moveBefore(&firstOp);
}
} else {
op->emitError("Unhandled case during fusion");
llvm_unreachable("Unhandled case during fusion");
Expand Down
Loading