1 //===-- mlir-c/ExecutionEngine.h - Execution engine management ---*- C -*-====//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 // This header provides basic access to the MLIR JIT. This is minimalist and
11 // experimental at the moment.
13 //===----------------------------------------------------------------------===//
15 #ifndef MLIR_C_EXECUTIONENGINE_H
16 #define MLIR_C_EXECUTIONENGINE_H
18 #include "mlir-c/IR.h"
19 #include "mlir-c/Support.h"
25 #define DEFINE_C_API_STRUCT(name, storage) \
29 typedef struct name name
31 DEFINE_C_API_STRUCT(MlirExecutionEngine
, void);
33 #undef DEFINE_C_API_STRUCT
35 /// Creates an ExecutionEngine for the provided ModuleOp. The ModuleOp is
36 /// expected to be "translatable" to LLVM IR (only contains operations in
37 /// dialects that implement the `LLVMTranslationDialectInterface`). The module
38 /// ownership stays with the client and can be destroyed as soon as the call
39 /// returns. `optLevel` is the optimization level to be used for transformation
40 /// and code generation. LLVM passes at `optLevel` are run before code
41 /// generation. The number and array of paths corresponding to shared libraries
42 /// that will be loaded are specified via `numPaths` and `sharedLibPaths`
44 /// TODO: figure out other options.
45 MLIR_CAPI_EXPORTED MlirExecutionEngine
mlirExecutionEngineCreate(
46 MlirModule op
, int optLevel
, int numPaths
,
47 const MlirStringRef
*sharedLibPaths
, bool enableObjectDump
);
49 /// Destroy an ExecutionEngine instance.
50 MLIR_CAPI_EXPORTED
void mlirExecutionEngineDestroy(MlirExecutionEngine jit
);
52 /// Checks whether an execution engine is null.
53 static inline bool mlirExecutionEngineIsNull(MlirExecutionEngine jit
) {
57 /// Invoke a native function in the execution engine by name with the arguments
58 /// and result of the invoked function passed as an array of pointers. The
59 /// function must have been tagged with the `llvm.emit_c_interface` attribute.
60 /// Returns a failure if the execution fails for any reason (the function name
61 /// can't be resolved for instance).
62 MLIR_CAPI_EXPORTED MlirLogicalResult
mlirExecutionEngineInvokePacked(
63 MlirExecutionEngine jit
, MlirStringRef name
, void **arguments
);
65 /// Lookup the wrapper of the native function in the execution engine with the
66 /// given name, returns nullptr if the function can't be looked-up.
67 MLIR_CAPI_EXPORTED
void *
68 mlirExecutionEngineLookupPacked(MlirExecutionEngine jit
, MlirStringRef name
);
70 /// Lookup a native function in the execution engine by name, returns nullptr
71 /// if the name can't be looked-up.
72 MLIR_CAPI_EXPORTED
void *mlirExecutionEngineLookup(MlirExecutionEngine jit
,
75 /// Register a symbol with the jit: this symbol will be accessible to the jitted
77 MLIR_CAPI_EXPORTED
void
78 mlirExecutionEngineRegisterSymbol(MlirExecutionEngine jit
, MlirStringRef name
,
81 /// Dump as an object in `fileName`.
82 MLIR_CAPI_EXPORTED
void
83 mlirExecutionEngineDumpToObjectFile(MlirExecutionEngine jit
,
84 MlirStringRef fileName
);
90 #endif // MLIR_C_EXECUTIONENGINE_H