Skip to content

Commit

Permalink
[mlir][bufferize] Simplify ModuleBufferization driver
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
matthias-springer committed Apr 6, 2022
1 parent 5ab3449 commit cd7de44
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
Expand Up @@ -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;

Expand All @@ -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 (failed(bufferizeOp(funcOp, bufferizationState)))
return failure();
}
if (!funcOp.getBody().empty())
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>();
Expand Down
Expand Up @@ -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
}
Expand Down

0 comments on commit cd7de44

Please sign in to comment.