@@ -88,7 +88,6 @@ getOrCreateFuncAnalysisState(OneShotAnalysisState &state) {
88
88
89
89
// / Return the unique ReturnOp that terminates `funcOp`.
90
90
// / Return nullptr if there is no such unique ReturnOp.
91
- // / Return `funcOp` it self if there is no ReturnOp.
92
91
static Operation* getAssumedUniqueReturnOp (FunctionOpInterface funcOp) {
93
92
Operation *returnOp = nullptr ;
94
93
for (Block &b : funcOp.getFunctionBody ()) {
@@ -99,8 +98,6 @@ static Operation* getAssumedUniqueReturnOp(FunctionOpInterface funcOp) {
99
98
returnOp = candidateOp;
100
99
}
101
100
}
102
- if (!returnOp)
103
- return funcOp;
104
101
return returnOp;
105
102
}
106
103
@@ -132,7 +129,7 @@ static void annotateEquivalentReturnBbArg(OpOperand &returnVal,
132
129
static LogicalResult
133
130
aliasingFuncOpBBArgsAnalysis (FunctionOpInterface funcOp, OneShotAnalysisState &state,
134
131
FuncAnalysisState &funcState) {
135
- if (funcOp.getFunctionBody ().empty ()) {
132
+ if (funcOp.getFunctionBody ().empty () || funcOp. getNumResults () == 0 ) {
136
133
// No function body available. Conservatively assume that every tensor
137
134
// return value may alias with any tensor bbArg.
138
135
for (const auto &inputIt : llvm::enumerate (funcOp.getArgumentTypes ())) {
@@ -150,10 +147,7 @@ aliasingFuncOpBBArgsAnalysis(FunctionOpInterface funcOp, OneShotAnalysisState &s
150
147
}
151
148
152
149
// Support only single return-terminated block in the function.
153
- // If funcOp has no returnOp, skip the following analysis.
154
150
Operation *returnOp = getAssumedUniqueReturnOp (funcOp);
155
- if (returnOp == funcOp)
156
- return success ();
157
151
assert (returnOp && " expected func with single return op" );
158
152
159
153
for (OpOperand &returnVal : returnOp->getOpOperands ())
@@ -304,9 +298,9 @@ getFuncOpsOrderedByCalls(ModuleOp moduleOp,
304
298
// For each FuncOp, the number of func::CallOp it contains.
305
299
DenseMap<FunctionOpInterface, unsigned > numberCallOpsContainedInFuncOp;
306
300
WalkResult res = moduleOp.walk ([&](FunctionOpInterface funcOp) -> WalkResult {
307
- if (!funcOp.getFunctionBody ().empty ()) {
301
+ if (!funcOp.getFunctionBody ().empty () && funcOp. getNumResults () != 0 ) {
308
302
Operation *returnOp = getAssumedUniqueReturnOp (funcOp);
309
- if (!returnOp && returnOp != funcOp )
303
+ if (!returnOp)
310
304
return funcOp->emitError ()
311
305
<< " cannot bufferize a FuncOp with tensors and "
312
306
" without a unique ReturnOp" ;
@@ -355,14 +349,10 @@ getFuncOpsOrderedByCalls(ModuleOp moduleOp,
355
349
// / entire function body, a more concise memref type can potentially be used for
356
350
// / the return type of the function.
357
351
static void foldMemRefCasts (FunctionOpInterface funcOp) {
358
- if (funcOp.getFunctionBody ().empty ())
352
+ if (funcOp.getFunctionBody ().empty () || funcOp. getNumResults () == 0 )
359
353
return ;
360
354
361
355
Operation *returnOp = getAssumedUniqueReturnOp (funcOp);
362
-
363
- if (!returnOp || returnOp == funcOp)
364
- return ;
365
-
366
356
SmallVector<Type> resultTypes;
367
357
368
358
for (OpOperand &operand : returnOp->getOpOperands ()) {
@@ -398,7 +388,6 @@ mlir::bufferization::analyzeModuleOp(ModuleOp moduleOp,
398
388
399
389
// Analyze ops.
400
390
for (FunctionOpInterface funcOp : orderedFuncOps) {
401
-
402
391
if (!state.getOptions ().isOpAllowed (funcOp))
403
392
continue ;
404
393
0 commit comments