diff --git a/mlir/lib/CAPI/ExecutionEngine/ExecutionEngine.cpp b/mlir/lib/CAPI/ExecutionEngine/ExecutionEngine.cpp --- a/mlir/lib/CAPI/ExecutionEngine/ExecutionEngine.cpp +++ b/mlir/lib/CAPI/ExecutionEngine/ExecutionEngine.cpp @@ -54,6 +54,7 @@ jitOptions.transformer = transformer; jitOptions.jitCodeGenOptLevel = llvmOptLevel; jitOptions.sharedLibPaths = libPaths; + jitOptions.enableObjectCache = true; auto jitOrError = ExecutionEngine::create(unwrap(op), jitOptions); if (!jitOrError) { consumeError(jitOrError.takeError()); diff --git a/mlir/test/python/execution_engine.py b/mlir/test/python/execution_engine.py --- a/mlir/test/python/execution_engine.py +++ b/mlir/test/python/execution_engine.py @@ -1,6 +1,6 @@ # RUN: %PYTHON %s 2>&1 | FileCheck %s # REQUIRES: host-supports-jit -import gc, sys +import gc, sys, os, tempfile from mlir.ir import * from mlir.passmanager import * from mlir.execution_engine import * @@ -552,3 +552,40 @@ run(testNanoTime) + + +# Test that nano time clock is available. +# CHECK-LABEL: TEST: testDumpToObjectFile +def testDumpToObjectFile(): + with Context(): + module = Module.parse(""" + module { + func.func @main() attributes { llvm.emit_c_interface } { + return + } + }""") + + execution_engine = ExecutionEngine( + lowerToLLVM(module), + opt_level=3) + + _, object_path = tempfile.mkstemp(suffix=".o") + + # CHECK: Object file exists: True + print(f"Object file exists: {os.path.exists(object_path)}") + # CHECK: Object file is empty: True + print(f"Object file is empty: {os.path.getsize(object_path) == 0}") + + execution_engine.invoke("main") + execution_engine.dump_to_object_file(object_path) + + # CHECK: Object file exists: True + print(f"Object file exists: {os.path.exists(object_path)}") + # CHECK: Object file is empty: False + print(f"Object file is empty: {os.path.getsize(object_path) == 0}") + + if os.path.exists(object_path): + os.remove(object_path) + + +run(testDumpToObjectFile)