Skip to content

Commit 26e69ad

Browse files
committed
Make getAssumedUniqueReturnOp return funcOp if there is no return
1 parent 1f8d847 commit 26e69ad

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

mlir/lib/Dialect/Bufferization/Transforms/OneShotModuleBufferize.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ getOrCreateFuncAnalysisState(OneShotAnalysisState &state) {
8888

8989
/// Return the unique ReturnOp that terminates `funcOp`.
9090
/// Return nullptr if there is no such unique ReturnOp.
91+
/// Return `funcOp` it self if there is no ReturnOp.
9192
static Operation* getAssumedUniqueReturnOp(FunctionOpInterface funcOp) {
9293
Operation *returnOp = nullptr;
9394
for (Block &b : funcOp.getFunctionBody()) {
@@ -98,6 +99,8 @@ static Operation* getAssumedUniqueReturnOp(FunctionOpInterface funcOp) {
9899
returnOp = candidateOp;
99100
}
100101
}
102+
if (!returnOp)
103+
return funcOp;
101104
return returnOp;
102105
}
103106

@@ -147,9 +150,10 @@ aliasingFuncOpBBArgsAnalysis(FunctionOpInterface funcOp, OneShotAnalysisState &s
147150
}
148151

149152
// Support only single return-terminated block in the function.
150-
if (!isa<func::FuncOp>(funcOp))
151-
return success();
153+
// If funcOp has no returnOp, skip the following analysis.
152154
Operation *returnOp = getAssumedUniqueReturnOp(funcOp);
155+
if (returnOp == funcOp)
156+
return success();
153157
assert(returnOp && "expected func with single return op");
154158

155159
for (OpOperand &returnVal : returnOp->getOpOperands())
@@ -300,9 +304,9 @@ getFuncOpsOrderedByCalls(ModuleOp moduleOp,
300304
// For each FuncOp, the number of func::CallOp it contains.
301305
DenseMap<FunctionOpInterface, unsigned> numberCallOpsContainedInFuncOp;
302306
WalkResult res = moduleOp.walk([&](FunctionOpInterface funcOp) -> WalkResult {
303-
if (!funcOp.getFunctionBody().empty() && isa<func::FuncOp>(funcOp)) {
307+
if (!funcOp.getFunctionBody().empty()) {
304308
Operation *returnOp = getAssumedUniqueReturnOp(funcOp);
305-
if (!returnOp)
309+
if (!returnOp && returnOp != funcOp)
306310
return funcOp->emitError()
307311
<< "cannot bufferize a FuncOp with tensors and "
308312
"without a unique ReturnOp";
@@ -356,7 +360,7 @@ static void foldMemRefCasts(FunctionOpInterface funcOp) {
356360

357361
Operation *returnOp = getAssumedUniqueReturnOp(funcOp);
358362

359-
if (!returnOp)
363+
if (!returnOp || returnOp == funcOp)
360364
return;
361365

362366
SmallVector<Type> resultTypes;

0 commit comments

Comments
 (0)