Skip to content

[MLIR] Make OneShotModuleBufferize use OpInterface #107295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

tzunghanjuang
Copy link
Contributor

@tzunghanjuang tzunghanjuang commented Sep 4, 2024

Description:

OneShotModuleBufferize deals with the bufferization of FuncOp, CallOp and ReturnOp but they are hard-coded. Any custom function-like operations will not be handled. The PR replaces a part of FuncOp and CallOp with FunctionOpInterface and CallOpInterface in OneShotModuleBufferize so that custom function ops and call ops can be bufferized.

Related Discord Discussion: Link

Copy link

github-actions bot commented Sep 4, 2024

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Sep 4, 2024

@llvm/pr-subscribers-mlir-linalg
@llvm/pr-subscribers-mlir-llvm
@llvm/pr-subscribers-mlir-bufferization

@llvm/pr-subscribers-mlir

Author: Tzung-Han Juang (tzunghanjuang)

Changes

Description:

OneShotModuleBufferize deals with the bufferization of FuncOp, CallOp and ReturnOp but they are hard-coded. Any custom function-like operations will not be handled. The PR replaces a part of FuncOp and CallOp with FunctionOpInterface and CallOpInterface in OneShotModuleBufferize so that custom function ops and call ops can be bufferized.

Limitations:

ReturnOp is not implemented with any interface. Right now we just create if cases for detecting FuncOp to trigger ReturnOp bufferization.

Related Discord Discussion: Link


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

1 Files Affected:

  • (modified) mlir/lib/Dialect/Bufferization/Transforms/OneShotModuleBufferize.cpp (+50-31)
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/OneShotModuleBufferize.cpp b/mlir/lib/Dialect/Bufferization/Transforms/OneShotModuleBufferize.cpp
index 0a4072605c265f..2983af0fcbf3f7 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/OneShotModuleBufferize.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/OneShotModuleBufferize.cpp
@@ -75,7 +75,7 @@ using namespace mlir::bufferization;
 using namespace mlir::bufferization::func_ext;
 
 /// A mapping of FuncOps to their callers.
-using FuncCallerMap = DenseMap<func::FuncOp, DenseSet<Operation *>>;
+using FuncCallerMap = DenseMap<FunctionOpInterface, DenseSet<Operation *>>;
 
 /// Get or create FuncAnalysisState.
 static FuncAnalysisState &
@@ -247,6 +247,15 @@ static func::FuncOp getCalledFunction(func::CallOp callOp) {
       SymbolTable::lookupNearestSymbolFrom(callOp, sym));
 }
 
+static FunctionOpInterface getCalledFunction(CallOpInterface callOp) {
+  SymbolRefAttr sym =
+      llvm::dyn_cast_if_present<SymbolRefAttr>(callOp.getCallableForCallee());
+  if (!sym)
+    return nullptr;
+  return dyn_cast_or_null<FunctionOpInterface>(
+      SymbolTable::lookupNearestSymbolFrom(callOp, sym));
+}
+
 /// Gather equivalence info of CallOps.
 /// Note: This only adds new equivalence info if the called function was already
 /// analyzed.
@@ -277,10 +286,10 @@ static void equivalenceAnalysis(func::FuncOp funcOp,
 }
 
 /// Return "true" if the given function signature has tensor semantics.
-static bool hasTensorSignature(func::FuncOp funcOp) {
-  return llvm::any_of(funcOp.getFunctionType().getInputs(),
+static bool hasTensorSignature(FunctionOpInterface funcOp) {
+  return llvm::any_of(funcOp.getArgumentTypes(),
                       llvm::IsaPred<TensorType>) ||
-         llvm::any_of(funcOp.getFunctionType().getResults(),
+         llvm::any_of(funcOp.getResultTypes(),
                       llvm::IsaPred<TensorType>);
 }
 
@@ -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)) {
+      FuncOp funcOpCasted = cast<FuncOp>(funcOp);
+      if (!funcOpCasted.getBody().empty()) {
+        func::ReturnOp returnOp = getAssumedUniqueReturnOp(funcOpCasted);
+        if (!returnOp)
+          return funcOp->emitError()
+                 << "cannot bufferize a FuncOp with tensors and "
+                    "without a unique ReturnOp";
+      }
     }
 
     // Collect function calls and populate the caller map.
     numberCallOpsContainedInFuncOp[funcOp] = 0;
-    return funcOp.walk([&](func::CallOp callOp) -> WalkResult {
-      func::FuncOp calledFunction = getCalledFunction(callOp);
+    return funcOp.walk([&](CallOpInterface callOp) -> WalkResult {
+      FunctionOpInterface calledFunction = getCalledFunction(callOp);
       assert(calledFunction && "could not retrieved called func::FuncOp");
       // If the called function does not have any tensors in its signature, then
       // it is not necessary to bufferize the callee before the caller.
@@ -379,7 +392,7 @@ mlir::bufferization::analyzeModuleOp(ModuleOp moduleOp,
   FuncAnalysisState &funcState = getOrCreateFuncAnalysisState(state);
 
   // A list of functions in the order in which they are analyzed + bufferized.
-  SmallVector<func::FuncOp> orderedFuncOps;
+  SmallVector<FunctionOpInterface> orderedFuncOps;
 
   // A mapping of FuncOps to their callers.
   FuncCallerMap callerMap;
@@ -388,27 +401,33 @@ mlir::bufferization::analyzeModuleOp(ModuleOp moduleOp,
     return failure();
 
   // Analyze ops.
-  for (func::FuncOp funcOp : orderedFuncOps) {
-    if (!state.getOptions().isOpAllowed(funcOp))
+  for (FunctionOpInterface funcOp : orderedFuncOps) {
+
+    // The following analysis is specific to the FuncOp type.
+    if(!isa<FuncOp>(funcOp))
+        continue;
+    FuncOp funcOpCasted = cast<func::FuncOp>(funcOp);
+
+    if (!state.getOptions().isOpAllowed(funcOpCasted))
       continue;
 
     // Now analyzing function.
-    funcState.startFunctionAnalysis(funcOp);
+    funcState.startFunctionAnalysis(funcOpCasted);
 
     // Gather equivalence info for CallOps.
-    equivalenceAnalysis(funcOp, state, funcState);
+    equivalenceAnalysis(funcOpCasted, state, funcState);
 
     // Analyze funcOp.
-    if (failed(analyzeOp(funcOp, state, statistics)))
+    if (failed(analyzeOp(funcOpCasted, state, statistics)))
       return failure();
 
     // Run some extra function analyses.
-    if (failed(aliasingFuncOpBBArgsAnalysis(funcOp, state, funcState)) ||
-        failed(funcOpBbArgReadWriteAnalysis(funcOp, state, funcState)))
+    if (failed(aliasingFuncOpBBArgsAnalysis(funcOpCasted, state, funcState)) ||
+        failed(funcOpBbArgReadWriteAnalysis(funcOpCasted, state, funcState)))
       return failure();
 
     // Mark op as fully analyzed.
-    funcState.analyzedFuncOps[funcOp] = FuncOpAnalysisState::Analyzed;
+    funcState.analyzedFuncOps[funcOpCasted] = FuncOpAnalysisState::Analyzed;
   }
 
   return success();
@@ -430,20 +449,20 @@ LogicalResult mlir::bufferization::bufferizeModuleOp(
   IRRewriter rewriter(moduleOp.getContext());
 
   // A list of functions in the order in which they are analyzed + bufferized.
-  SmallVector<func::FuncOp> orderedFuncOps;
+  SmallVector<FunctionOpInterface> orderedFuncOps;
 
   // A mapping of FuncOps to their callers.
   FuncCallerMap callerMap;
 
   if (failed(getFuncOpsOrderedByCalls(moduleOp, orderedFuncOps, callerMap)))
     return failure();
+  SmallVector<FunctionOpInterface> ops;
 
   // Bufferize functions.
-  for (func::FuncOp funcOp : orderedFuncOps) {
+  for (FunctionOpInterface funcOp : orderedFuncOps) {
     // Note: It would be good to apply cleanups here but we cannot as aliasInfo
     // would be invalidated.
-
-    if (llvm::is_contained(options.noAnalysisFuncFilter, funcOp.getSymName())) {
+    if (llvm::is_contained(options.noAnalysisFuncFilter, funcOp.getName())) {
       // This function was not analyzed and RaW conflicts were not resolved.
       // Buffer copies must be inserted before every write.
       OneShotBufferizationOptions updatedOptions = options;
@@ -456,8 +475,8 @@ LogicalResult mlir::bufferization::bufferizeModuleOp(
     }
 
     // Change buffer return types to more precise layout maps.
-    if (options.inferFunctionResultLayout)
-      foldMemRefCasts(funcOp);
+    if (options.inferFunctionResultLayout && isa<func::FuncOp>(funcOp))
+      foldMemRefCasts(cast<func::FuncOp>(funcOp));
   }
 
   // Bufferize all other ops.

@tzunghanjuang
Copy link
Contributor Author

Hi @matthias-springer , this PR is ready to merge but we do not have any write access. Could you please merge this for us? Thank you very much.

Copy link

github-actions bot commented Sep 24, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@matthias-springer matthias-springer merged commit f586b1e into llvm:main Sep 25, 2024
8 checks passed
Copy link

@tzunghanjuang Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 25, 2024

LLVM Buildbot has detected a new failure on builder mlir-rocm-mi200 running on mi200-buildbot while building mlir at step 6 "test-build-check-mlir-build-only-check-mlir".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/177/builds/5589

Here is the relevant piece of the build log for the reference
Step 6 (test-build-check-mlir-build-only-check-mlir) failure: test (failure)
******************** TEST 'MLIR :: Integration/Dialect/Complex/CPU/correctness.mlir' FAILED ********************
Exit Code: 2

Command Output (stdout):
--
# RUN: at line 1
/vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/mlir-opt /vol/worker/mi200-buildbot/mlir-rocm-mi200/llvm-project/mlir/test/Integration/Dialect/Complex/CPU/correctness.mlir    -one-shot-bufferize="bufferize-function-boundaries" --canonicalize    -convert-scf-to-cf --convert-complex-to-standard    -finalize-memref-to-llvm -convert-math-to-llvm -convert-math-to-libm    -convert-vector-to-llvm -convert-complex-to-llvm    -convert-func-to-llvm -reconcile-unrealized-casts | /vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/mlir-cpu-runner   -e entry -entry-point-result=void    -shared-libs=/vol/worker/mi200-buildbot/mlir-rocm-mi200/build/lib/libmlir_c_runner_utils.so | /vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/FileCheck /vol/worker/mi200-buildbot/mlir-rocm-mi200/llvm-project/mlir/test/Integration/Dialect/Complex/CPU/correctness.mlir
# executed command: /vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/mlir-opt /vol/worker/mi200-buildbot/mlir-rocm-mi200/llvm-project/mlir/test/Integration/Dialect/Complex/CPU/correctness.mlir -one-shot-bufferize=bufferize-function-boundaries --canonicalize -convert-scf-to-cf --convert-complex-to-standard -finalize-memref-to-llvm -convert-math-to-llvm -convert-math-to-libm -convert-vector-to-llvm -convert-complex-to-llvm -convert-func-to-llvm -reconcile-unrealized-casts
# .---command stderr------------
# | mlir-opt: /vol/worker/mi200-buildbot/mlir-rocm-mi200/llvm-project/mlir/lib/Dialect/Bufferization/Transforms/OneShotModuleBufferize.cpp:313: auto getFuncOpsOrderedByCalls(ModuleOp, SmallVectorImpl<FunctionOpInterface> &, FuncCallerMap &)::(anonymous class)::operator()(FunctionOpInterface)::(anonymous class)::operator()(CallOpInterface) const: Assertion `calledFunction && "could not retrieved called FunctionOpInterface"' failed.
# | PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
# | Stack dump:
# | 0.	Program arguments: /vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/mlir-opt /vol/worker/mi200-buildbot/mlir-rocm-mi200/llvm-project/mlir/test/Integration/Dialect/Complex/CPU/correctness.mlir -one-shot-bufferize=bufferize-function-boundaries --canonicalize -convert-scf-to-cf --convert-complex-to-standard -finalize-memref-to-llvm -convert-math-to-llvm -convert-math-to-libm -convert-vector-to-llvm -convert-complex-to-llvm -convert-func-to-llvm -reconcile-unrealized-casts
# |  #0 0x0000561dcb56d7b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/mlir-opt+0x405d7b8)
# |  #1 0x0000561dcb56b2ae llvm::sys::RunSignalHandlers() (/vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/mlir-opt+0x405b2ae)
# |  #2 0x0000561dcb56df9d SignalHandler(int) Signals.cpp:0:0
# |  #3 0x00007fc465ca6420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
# |  #4 0x00007fc46576900b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
# |  #5 0x00007fc465748859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
# |  #6 0x00007fc465748729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
# |  #7 0x00007fc465759fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
# |  #8 0x0000561dcba6915d mlir::WalkResult llvm::function_ref<mlir::WalkResult (mlir::Operation*)>::callback_fn<std::enable_if<!llvm::is_one_of<mlir::CallOpInterface, mlir::Operation*, mlir::Region*, mlir::Block*>::value && std::is_same<mlir::WalkResult, mlir::WalkResult>::value, mlir::WalkResult>::type mlir::detail::walk<(mlir::WalkOrder)1, mlir::ForwardIterator, getFuncOpsOrderedByCalls(mlir::ModuleOp, llvm::SmallVectorImpl<mlir::FunctionOpInterface>&, llvm::DenseMap<mlir::FunctionOpInterface, llvm::DenseSet<mlir::Operation*, llvm::DenseMapInfo<mlir::Operation*, void>>, llvm::DenseMapInfo<mlir::FunctionOpInterface, void>, llvm::detail::DenseMapPair<mlir::FunctionOpInterface, llvm::DenseSet<mlir::Operation*, llvm::DenseMapInfo<mlir::Operation*, void>>>>&)::$_1::operator()(mlir::FunctionOpInterface) const::'lambda'(mlir::CallOpInterface), mlir::CallOpInterface, mlir::WalkResult>(mlir::Operation*, getFuncOpsOrderedByCalls(mlir::ModuleOp, llvm::SmallVectorImpl<mlir::FunctionOpInterface>&, llvm::DenseMap<mlir::FunctionOpInterface, llvm::DenseSet<mlir::Operation*, llvm::DenseMapInfo<mlir::Operation*, void>>, llvm::DenseMapInfo<mlir::FunctionOpInterface, void>, llvm::detail::DenseMapPair<mlir::FunctionOpInterface, llvm::DenseSet<mlir::Operation*, llvm::DenseMapInfo<mlir::Operation*, void>>>>&)::$_1::operator()(mlir::FunctionOpInterface) const::'lambda'(mlir::CallOpInterface)&&)::'lambda'(mlir::Operation*)>(long, mlir::Operation*) OneShotModuleBufferize.cpp:0:0
# |  #9 0x0000561dcb5f48a7 mlir::WalkResult mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) (/vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/mlir-opt+0x40e48a7)
# | #10 0x0000561dcb5f48a7 mlir::WalkResult mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) (/vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/mlir-opt+0x40e48a7)
# | #11 0x0000561dcba689d6 mlir::WalkResult llvm::function_ref<mlir::WalkResult (mlir::Operation*)>::callback_fn<std::enable_if<!llvm::is_one_of<mlir::FunctionOpInterface, mlir::Operation*, mlir::Region*, mlir::Block*>::value && std::is_same<mlir::WalkResult, mlir::WalkResult>::value, mlir::WalkResult>::type mlir::detail::walk<(mlir::WalkOrder)1, mlir::ForwardIterator, getFuncOpsOrderedByCalls(mlir::ModuleOp, llvm::SmallVectorImpl<mlir::FunctionOpInterface>&, llvm::DenseMap<mlir::FunctionOpInterface, llvm::DenseSet<mlir::Operation*, llvm::DenseMapInfo<mlir::Operation*, void>>, llvm::DenseMapInfo<mlir::FunctionOpInterface, void>, llvm::detail::DenseMapPair<mlir::FunctionOpInterface, llvm::DenseSet<mlir::Operation*, llvm::DenseMapInfo<mlir::Operation*, void>>>>&)::$_1, mlir::FunctionOpInterface, mlir::WalkResult>(mlir::Operation*, getFuncOpsOrderedByCalls(mlir::ModuleOp, llvm::SmallVectorImpl<mlir::FunctionOpInterface>&, llvm::DenseMap<mlir::FunctionOpInterface, llvm::DenseSet<mlir::Operation*, llvm::DenseMapInfo<mlir::Operation*, void>>, llvm::DenseMapInfo<mlir::FunctionOpInterface, void>, llvm::detail::DenseMapPair<mlir::FunctionOpInterface, llvm::DenseSet<mlir::Operation*, llvm::DenseMapInfo<mlir::Operation*, void>>>>&)::$_1&&)::'lambda'(mlir::Operation*)>(long, mlir::Operation*) OneShotModuleBufferize.cpp:0:0
# | #12 0x0000561dcb5f48a7 mlir::WalkResult mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) (/vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/mlir-opt+0x40e48a7)
# | #13 0x0000561dcba66df7 getFuncOpsOrderedByCalls(mlir::ModuleOp, llvm::SmallVectorImpl<mlir::FunctionOpInterface>&, llvm::DenseMap<mlir::FunctionOpInterface, llvm::DenseSet<mlir::Operation*, llvm::DenseMapInfo<mlir::Operation*, void>>, llvm::DenseMapInfo<mlir::FunctionOpInterface, void>, llvm::detail::DenseMapPair<mlir::FunctionOpInterface, llvm::DenseSet<mlir::Operation*, llvm::DenseMapInfo<mlir::Operation*, void>>>>&) OneShotModuleBufferize.cpp:0:0
# | #14 0x0000561dcba6544e mlir::bufferization::analyzeModuleOp(mlir::ModuleOp, mlir::bufferization::OneShotAnalysisState&, mlir::bufferization::BufferizationStatistics*) (/vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/mlir-opt+0x455544e)
# | #15 0x0000561dcba73a1b mlir::bufferization::insertTensorCopies(mlir::Operation*, mlir::bufferization::OneShotBufferizationOptions const&, mlir::bufferization::BufferizationStatistics*) (/vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/mlir-opt+0x4563a1b)
# | #16 0x0000561dcba67eac mlir::bufferization::runOneShotModuleBufferize(mlir::ModuleOp, mlir::bufferization::OneShotBufferizationOptions const&, mlir::bufferization::BufferizationStatistics*) (/vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/mlir-opt+0x4557eac)
# | #17 0x0000561dcba3122f (anonymous namespace)::OneShotBufferizePass::runOnOperation() Bufferize.cpp:0:0
# | #18 0x0000561dce89c3a6 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/mlir-opt+0x738c3a6)
# | #19 0x0000561dce89cbd2 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/mlir-opt+0x738cbd2)
# | #20 0x0000561dce89f13e mlir::PassManager::run(mlir::Operation*) (/vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/mlir-opt+0x738f13e)
# | #21 0x0000561dce897c12 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
# | #22 0x0000561dce89786b llvm::LogicalResult llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_0>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) MlirOptMain.cpp:0:0
# | #23 0x0000561dce94d275 mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (/vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/mlir-opt+0x743d275)
# | #24 0x0000561dce892d12 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/mlir-opt+0x7382d12)
# | #25 0x0000561dce892fc3 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/mlir-opt+0x7382fc3)
# | #26 0x0000561dce8932de mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/mlir-opt+0x73832de)
# | #27 0x0000561dcb4beee7 main (/vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/mlir-opt+0x3faeee7)
# | #28 0x00007fc46574a083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
# | #29 0x0000561dcb4bea6e _start (/vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/mlir-opt+0x3faea6e)
# `-----------------------------
# error: command failed with exit status: -6
# executed command: /vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/mlir-cpu-runner -e entry -entry-point-result=void -shared-libs=/vol/worker/mi200-buildbot/mlir-rocm-mi200/build/lib/libmlir_c_runner_utils.so
# .---command stderr------------
# | Error: entry point not found
# `-----------------------------
# error: command failed with exit status: 1
...

matthias-springer added a commit that referenced this pull request Sep 25, 2024
matthias-springer added a commit that referenced this pull request Sep 25, 2024
)

Reverts #107295

This commit breaks an integration test:
```
build/bin/mlir-opt mlir/test/Integration/Dialect/Complex/CPU/correctness.mlir  -one-shot-bufferize="bufferize-function-boundaries"
```
@matthias-springer
Copy link
Member

@tzunghanjuang This broke an integration test. Can you take fix it an reopen this PR, then I'm going to merge the fixed PR again.

@tzunghanjuang
Copy link
Contributor Author

Hi @matthias-springer , the error is triggered by CallIndirectOp. Since the function called by CallIndirectOp cannot be known statically, getCalledFunction will return nullptr and then break the assertion. We fixed it by making the function analysis skip CallIndirectOp. Do you have any suggestions for handling this case? Thank you.

@tzunghanjuang
Copy link
Contributor Author

I do not have the access to reopen this PR. I create a new one with the fix: #110322.

matthias-springer pushed a commit that referenced this pull request Oct 1, 2024
**Description:** 
This PR replaces a part of `FuncOp` and `CallOp` with
`FunctionOpInterface` and `CallOpInterface` in `OneShotModuleBufferize`.
Also fix the error from an integration test in the a previous PR
attempt. (#107295)

The below fixes skip `CallOpInterface` so that the assertions are not
triggered.


https://github.com/llvm/llvm-project/blob/8d780007625108a7f34e40efb8604b858e04c60c/mlir/lib/Dialect/Bufferization/Transforms/OneShotModuleBufferize.cpp#L254-L259


https://github.com/llvm/llvm-project/blob/8d780007625108a7f34e40efb8604b858e04c60c/mlir/lib/Dialect/Bufferization/Transforms/OneShotModuleBufferize.cpp#L311-L315

**Related Discord Discussion:**
[Link](https://discord.com/channels/636084430946959380/642426447167881246/1280556809911799900)

---------

Co-authored-by: erick-xanadu <[email protected]>
puja2196 pushed a commit to puja2196/LLVM-tutorial that referenced this pull request Oct 2, 2024
**Description:** 
This PR replaces a part of `FuncOp` and `CallOp` with
`FunctionOpInterface` and `CallOpInterface` in `OneShotModuleBufferize`.
Also fix the error from an integration test in the a previous PR
attempt. (llvm/llvm-project#107295)

The below fixes skip `CallOpInterface` so that the assertions are not
triggered.


https://github.com/llvm/llvm-project/blob/8d780007625108a7f34e40efb8604b858e04c60c/mlir/lib/Dialect/Bufferization/Transforms/OneShotModuleBufferize.cpp#L254-L259


https://github.com/llvm/llvm-project/blob/8d780007625108a7f34e40efb8604b858e04c60c/mlir/lib/Dialect/Bufferization/Transforms/OneShotModuleBufferize.cpp#L311-L315

**Related Discord Discussion:**
[Link](https://discord.com/channels/636084430946959380/642426447167881246/1280556809911799900)

---------

Co-authored-by: erick-xanadu <[email protected]>
Sterling-Augustine pushed a commit to Sterling-Augustine/llvm-project that referenced this pull request Oct 3, 2024
**Description:** 
This PR replaces a part of `FuncOp` and `CallOp` with
`FunctionOpInterface` and `CallOpInterface` in `OneShotModuleBufferize`.
Also fix the error from an integration test in the a previous PR
attempt. (llvm#107295)

The below fixes skip `CallOpInterface` so that the assertions are not
triggered.


https://github.com/llvm/llvm-project/blob/8d780007625108a7f34e40efb8604b858e04c60c/mlir/lib/Dialect/Bufferization/Transforms/OneShotModuleBufferize.cpp#L254-L259


https://github.com/llvm/llvm-project/blob/8d780007625108a7f34e40efb8604b858e04c60c/mlir/lib/Dialect/Bufferization/Transforms/OneShotModuleBufferize.cpp#L311-L315

**Related Discord Discussion:**
[Link](https://discord.com/channels/636084430946959380/642426447167881246/1280556809911799900)

---------

Co-authored-by: erick-xanadu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants