[Mlir-commits] [mlir] cd9d487 - [MLIR][ExecutionEngine] don't dump decls (#164478)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Oct 27 12:22:17 PDT 2025
Author: Maksim Levental
Date: 2025-10-27T12:22:13-07:00
New Revision: cd9d48777e3b1f2d46791e7d834a80f1b6a14c74
URL: https://github.com/llvm/llvm-project/commit/cd9d48777e3b1f2d46791e7d834a80f1b6a14c74
DIFF: https://github.com/llvm/llvm-project/commit/cd9d48777e3b1f2d46791e7d834a80f1b6a14c74.diff
LOG: [MLIR][ExecutionEngine] don't dump decls (#164478)
Currently ExecutionEngine tries to dump all functions declared in the
module, even those which are "external" (i.e., linked/loaded at
runtime). E.g.
```mlir
func.func private @printF32(f32)
func.func @supported_arg_types(%arg0: i32, %arg1: f32) {
call @printF32(%arg1) : (f32) -> ()
return
}
```
fails with
```
Could not compile printF32:
Symbols not found: [ __mlir_printF32 ]
Program aborted due to an unhandled Error:
Symbols not found: [ __mlir_printF32 ]
```
even though `printF32` can be provided at final build time (i.e., when
the object file is linked to some executable or shlib). E.g, if our own
`libmlir_c_runner_utils` is linked.
So just skip functions which have no bodies during dump (i.e., are decls
without defns).
Added:
Modified:
mlir/lib/ExecutionEngine/ExecutionEngine.cpp
mlir/test/python/CMakeLists.txt
mlir/test/python/execution_engine.py
Removed:
################################################################################
diff --git a/mlir/lib/ExecutionEngine/ExecutionEngine.cpp b/mlir/lib/ExecutionEngine/ExecutionEngine.cpp
index 52162a43aeae3..2255633c746b3 100644
--- a/mlir/lib/ExecutionEngine/ExecutionEngine.cpp
+++ b/mlir/lib/ExecutionEngine/ExecutionEngine.cpp
@@ -239,6 +239,8 @@ ExecutionEngine::create(Operation *m, const ExecutionEngineOptions &options,
// Remember all entry-points if object dumping is enabled.
if (options.enableObjectDump) {
for (auto funcOp : m->getRegion(0).getOps<LLVM::LLVMFuncOp>()) {
+ if (funcOp.getBlocks().empty())
+ continue;
StringRef funcName = funcOp.getSymName();
engine->functionNames.push_back(funcName.str());
}
diff --git a/mlir/test/python/CMakeLists.txt b/mlir/test/python/CMakeLists.txt
index e1e82ef367b1e..2c123811c2998 100644
--- a/mlir/test/python/CMakeLists.txt
+++ b/mlir/test/python/CMakeLists.txt
@@ -11,7 +11,7 @@ add_public_tablegen_target(MLIRPythonTestIncGen)
add_subdirectory(lib)
-set(MLIR_PYTHON_TEST_DEPENDS MLIRPythonModules)
+set(MLIR_PYTHON_TEST_DEPENDS MLIRPythonModules mlir-runner)
if(NOT MLIR_STANDALONE_BUILD)
list(APPEND MLIR_PYTHON_TEST_DEPENDS FileCheck count not)
endif()
diff --git a/mlir/test/python/execution_engine.py b/mlir/test/python/execution_engine.py
index d569fcef32bfd..146e213a9229e 100644
--- a/mlir/test/python/execution_engine.py
+++ b/mlir/test/python/execution_engine.py
@@ -1,6 +1,7 @@
# RUN: env MLIR_RUNNER_UTILS=%mlir_runner_utils MLIR_C_RUNNER_UTILS=%mlir_c_runner_utils %PYTHON %s 2>&1 | FileCheck %s
# REQUIRES: host-supports-jit
import gc, sys, os, tempfile
+from textwrap import dedent
from mlir.ir import *
from mlir.passmanager import *
from mlir.execution_engine import *
@@ -21,6 +22,7 @@
"MLIR_C_RUNNER_UTILS", "../../../../lib/libmlir_c_runner_utils.so"
)
+
# Log everything to stderr and flush so that we have a unified stream to match
# errors/info emitted by MLIR to stderr.
def log(*args):
@@ -337,6 +339,7 @@ def callback(a):
ctypes.pointer(ctypes.pointer(get_ranked_memref_descriptor(inp_arr))),
)
+
run(testUnrankedMemRefWithOffsetCallback)
@@ -785,15 +788,25 @@ def testDumpToObjectFile():
try:
with Context():
module = Module.parse(
- """
- module {
- func.func @main() attributes { llvm.emit_c_interface } {
- return
- }
- }"""
+ dedent(
+ """
+ func.func private @printF32(f32)
+ func.func @main(%arg0: f32) attributes { llvm.emit_c_interface } {
+ call @printF32(%arg0) : (f32) -> ()
+ return
+ }
+ """
+ )
)
- execution_engine = ExecutionEngine(lowerToLLVM(module), opt_level=3)
+ execution_engine = ExecutionEngine(
+ lowerToLLVM(module),
+ opt_level=3,
+ # Loading MLIR_C_RUNNER_UTILS is necessary even though we don't actually run the code (i.e., call printF32)
+ # because RTDyldObjectLinkingLayer::emit will try to resolve symbols before dumping
+ # (see the jitLinkForORC call at the bottom there).
+ shared_libs=[MLIR_C_RUNNER_UTILS],
+ )
# CHECK: Object file exists: True
print(f"Object file exists: {os.path.exists(object_path)}")
More information about the Mlir-commits
mailing list