Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ LogicalResult
mlir::bufferization::dropEquivalentBufferResults(ModuleOp module) {
IRRewriter rewriter(module.getContext());

DenseMap<func::FuncOp, DenseSet<func::CallOp>> callerMap;
// Collect the mapping of functions to their call sites.
module.walk([&](func::CallOp callOp) {
if (func::FuncOp calledFunc = getCalledFunction(callOp)) {
callerMap[calledFunc].insert(callOp);
}
});

for (auto funcOp : module.getOps<func::FuncOp>()) {
if (funcOp.isExternal())
continue;
Expand Down Expand Up @@ -109,10 +117,7 @@ mlir::bufferization::dropEquivalentBufferResults(ModuleOp module) {
returnOp.getOperandsMutable().assign(newReturnValues);

// Update function calls.
module.walk([&](func::CallOp callOp) {
if (getCalledFunction(callOp) != funcOp)
return WalkResult::skip();

for (func::CallOp callOp : callerMap[funcOp]) {
rewriter.setInsertionPoint(callOp);
auto newCallOp = rewriter.create<func::CallOp>(callOp.getLoc(), funcOp,
callOp.getOperands());
Expand All @@ -136,8 +141,7 @@ mlir::bufferization::dropEquivalentBufferResults(ModuleOp module) {
newResults.push_back(replacement);
}
rewriter.replaceOp(callOp, newResults);
return WalkResult::advance();
});
}
}

return success();
Expand Down