Skip to content

Commit 074192c

Browse files
committed
Use getNumResults to guard functions without any return type
1 parent 26e69ad commit 074192c

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

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

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ 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.
9291
static Operation* getAssumedUniqueReturnOp(FunctionOpInterface funcOp) {
9392
Operation *returnOp = nullptr;
9493
for (Block &b : funcOp.getFunctionBody()) {
@@ -99,8 +98,6 @@ static Operation* getAssumedUniqueReturnOp(FunctionOpInterface funcOp) {
9998
returnOp = candidateOp;
10099
}
101100
}
102-
if (!returnOp)
103-
return funcOp;
104101
return returnOp;
105102
}
106103

@@ -132,7 +129,7 @@ static void annotateEquivalentReturnBbArg(OpOperand &returnVal,
132129
static LogicalResult
133130
aliasingFuncOpBBArgsAnalysis(FunctionOpInterface funcOp, OneShotAnalysisState &state,
134131
FuncAnalysisState &funcState) {
135-
if (funcOp.getFunctionBody().empty()) {
132+
if (funcOp.getFunctionBody().empty() || funcOp.getNumResults() == 0) {
136133
// No function body available. Conservatively assume that every tensor
137134
// return value may alias with any tensor bbArg.
138135
for (const auto &inputIt : llvm::enumerate(funcOp.getArgumentTypes())) {
@@ -150,10 +147,7 @@ aliasingFuncOpBBArgsAnalysis(FunctionOpInterface funcOp, OneShotAnalysisState &s
150147
}
151148

152149
// Support only single return-terminated block in the function.
153-
// If funcOp has no returnOp, skip the following analysis.
154150
Operation *returnOp = getAssumedUniqueReturnOp(funcOp);
155-
if (returnOp == funcOp)
156-
return success();
157151
assert(returnOp && "expected func with single return op");
158152

159153
for (OpOperand &returnVal : returnOp->getOpOperands())
@@ -304,9 +298,9 @@ getFuncOpsOrderedByCalls(ModuleOp moduleOp,
304298
// For each FuncOp, the number of func::CallOp it contains.
305299
DenseMap<FunctionOpInterface, unsigned> numberCallOpsContainedInFuncOp;
306300
WalkResult res = moduleOp.walk([&](FunctionOpInterface funcOp) -> WalkResult {
307-
if (!funcOp.getFunctionBody().empty()) {
301+
if (!funcOp.getFunctionBody().empty() && funcOp.getNumResults() != 0) {
308302
Operation *returnOp = getAssumedUniqueReturnOp(funcOp);
309-
if (!returnOp && returnOp != funcOp)
303+
if (!returnOp)
310304
return funcOp->emitError()
311305
<< "cannot bufferize a FuncOp with tensors and "
312306
"without a unique ReturnOp";
@@ -355,14 +349,10 @@ getFuncOpsOrderedByCalls(ModuleOp moduleOp,
355349
/// entire function body, a more concise memref type can potentially be used for
356350
/// the return type of the function.
357351
static void foldMemRefCasts(FunctionOpInterface funcOp) {
358-
if (funcOp.getFunctionBody().empty())
352+
if (funcOp.getFunctionBody().empty() || funcOp.getNumResults() == 0)
359353
return;
360354

361355
Operation *returnOp = getAssumedUniqueReturnOp(funcOp);
362-
363-
if (!returnOp || returnOp == funcOp)
364-
return;
365-
366356
SmallVector<Type> resultTypes;
367357

368358
for (OpOperand &operand : returnOp->getOpOperands()) {
@@ -398,7 +388,6 @@ mlir::bufferization::analyzeModuleOp(ModuleOp moduleOp,
398388

399389
// Analyze ops.
400390
for (FunctionOpInterface funcOp : orderedFuncOps) {
401-
402391
if (!state.getOptions().isOpAllowed(funcOp))
403392
continue;
404393

0 commit comments

Comments
 (0)