forked from OSchip/llvm-project
[mlir][bufferize] Simplify ModuleBufferization driver
* Bufferize FuncOp bodies and boundaries in the same loop. This is in preparation of moving FuncOp bufferization into an external model implementation. * As a side effect, stop bufferization earlier if there was an error. (Do not continue bufferization, fewer error messages.) * Run equivalence analysis of CallOps before the main analysis. This is needed so that equialvence info is propagated properly. Differential Revision: https://reviews.llvm.org/D123208
This commit is contained in:
parent
5ab34492d6
commit
cd7de446fd
|
@ -1033,14 +1033,13 @@ LogicalResult mlir::linalg::comprehensive_bufferize::runModuleBufferize(
|
|||
// Now analyzing function.
|
||||
moduleState.startFunctionAnalysis(funcOp);
|
||||
|
||||
// Gather equivalence info for CallOps.
|
||||
equivalenceAnalysis(funcOp, aliasInfo, moduleState);
|
||||
|
||||
// Analyze funcOp.
|
||||
if (failed(analyzeOp(funcOp, analysisState)))
|
||||
return failure();
|
||||
|
||||
// Gather equivalence info for CallOps.
|
||||
// TODO: Make this a post-analysis step.
|
||||
equivalenceAnalysis(funcOp, aliasInfo, moduleState);
|
||||
|
||||
// Mark op as fully analyzed.
|
||||
moduleState.analyzedFuncOps[funcOp] = FuncOpAnalysisState::Analyzed;
|
||||
|
||||
|
@ -1052,23 +1051,21 @@ LogicalResult mlir::linalg::comprehensive_bufferize::runModuleBufferize(
|
|||
if (options.testAnalysisOnly)
|
||||
return success();
|
||||
|
||||
// Bufferize function bodies.
|
||||
// Bufferize functions.
|
||||
for (FuncOp funcOp : moduleState.orderedFuncOps) {
|
||||
// No body => no analysis.
|
||||
if (funcOp.getBody().empty())
|
||||
continue;
|
||||
if (!funcOp.getBody().empty())
|
||||
if (failed(bufferizeOp(funcOp, bufferizationState)))
|
||||
return failure();
|
||||
|
||||
if (failed(bufferizeOp(funcOp, bufferizationState)))
|
||||
return failure();
|
||||
}
|
||||
|
||||
// Bufferize function boundaries.
|
||||
for (FuncOp funcOp : moduleState.orderedFuncOps) {
|
||||
// Note: It would be good to apply cleanups here but we cannot as aliasInfo
|
||||
// would be invalidated.
|
||||
if (failed(bufferizeFuncOpBoundary(funcOp, rewriter, bufferizationState)))
|
||||
return failure();
|
||||
}
|
||||
|
||||
// Check result.
|
||||
for (FuncOp funcOp : moduleState.orderedFuncOps) {
|
||||
if (!options.allowReturnAllocs &&
|
||||
llvm::any_of(funcOp.getFunctionType().getResults(), [](Type t) {
|
||||
return t.isa<MemRefType, UnrankedMemRefType>();
|
||||
|
|
|
@ -212,11 +212,10 @@ func @to_memref_op_is_writing(
|
|||
|
||||
// -----
|
||||
|
||||
// expected-error @+1 {{cannot bufferize bodiless function that returns a tensor}}
|
||||
func private @foo(%t : tensor<?xf32>) -> (f32, tensor<?xf32>, f32)
|
||||
|
||||
func @call_to_unknown_tensor_returning_func(%t : tensor<?xf32>) {
|
||||
// expected-error @+2 {{call to FuncOp that returns non-equivalent tensors not supported}}
|
||||
// expected-error @+1 {{op was not bufferized}}
|
||||
call @foo(%t) : (tensor<?xf32>) -> (f32, tensor<?xf32>, f32)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue