[Mlir-commits] [mlir] [MLIR] Make `OneShotModuleBufferize` use `OpInterface` (PR #107295)

Tzung-Han Juang llvmlistbot at llvm.org
Fri Sep 6 08:05:10 PDT 2024


================
@@ -291,26 +300,30 @@ static bool hasTensorSignature(func::FuncOp funcOp) {
 /// retrieve the called FuncOp from any func::CallOp.
 static LogicalResult
 getFuncOpsOrderedByCalls(ModuleOp moduleOp,
-                         SmallVectorImpl<func::FuncOp> &orderedFuncOps,
+                         SmallVectorImpl<FunctionOpInterface> &orderedFuncOps,
                          FuncCallerMap &callerMap) {
   // For each FuncOp, the set of functions called by it (i.e. the union of
   // symbols of all nested func::CallOp).
-  DenseMap<func::FuncOp, DenseSet<func::FuncOp>> calledBy;
+  DenseMap<FunctionOpInterface, DenseSet<FunctionOpInterface>> calledBy;
   // For each FuncOp, the number of func::CallOp it contains.
-  DenseMap<func::FuncOp, unsigned> numberCallOpsContainedInFuncOp;
-  WalkResult res = moduleOp.walk([&](func::FuncOp funcOp) -> WalkResult {
-    if (!funcOp.getBody().empty()) {
-      func::ReturnOp returnOp = getAssumedUniqueReturnOp(funcOp);
-      if (!returnOp)
-        return funcOp->emitError()
-               << "cannot bufferize a FuncOp with tensors and "
-                  "without a unique ReturnOp";
+  DenseMap<FunctionOpInterface, unsigned> numberCallOpsContainedInFuncOp;
+  WalkResult res = moduleOp.walk([&](FunctionOpInterface funcOp) -> WalkResult {
+    // Only handle ReturnOp if funcOp is exactly the FuncOp type.
+    if(isa<FuncOp>(funcOp)) {
----------------
tzunghanjuang wrote:

Hi, we have made `getAssumedUniqueReturnOp` to detect `ReturnLike` ops and made it return `funcOp` if there is no `ReturnLike` op. When it returns `funcOp` ifselt, the analysis in `aliasingFuncOpBBArgsAnalysis` and `foldMemRefCasts` will be skipped.

In summary, we think there are 3 scenarios:
- Exaclty one `ReturnLike` op => Perform the return-related analysis.
- No `ReturnLike` op  => Skip the analysis. No error is thrown.
- Multiple `ReturnLike` ops => Throw an error.


https://github.com/llvm/llvm-project/pull/107295


More information about the Mlir-commits mailing list