1 //===-- mlir-c/ExecutionEngine.h - Execution engine management ---*- C -*-====// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 4 // Exceptions. 5 // See https://llvm.org/LICENSE.txt for license information. 6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This header provides basic access to the MLIR JIT. This is minimalist and 11 // experimental at the moment. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #ifndef MLIR_C_EXECUTIONENGINE_H 16 #define MLIR_C_EXECUTIONENGINE_H 17 18 #include "mlir-c/IR.h" 19 #include "mlir-c/Support.h" 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 #define DEFINE_C_API_STRUCT(name, storage) \ 26 struct name { \ 27 storage *ptr; \ 28 }; \ 29 typedef struct name name 30 31 DEFINE_C_API_STRUCT(MlirExecutionEngine, void); 32 33 #undef DEFINE_C_API_STRUCT 34 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. 40 /// TODO: figure out options (optimization level, etc.). 41 MLIR_CAPI_EXPORTED MlirExecutionEngine mlirExecutionEngineCreate(MlirModule op); 42 43 /// Destroy an ExecutionEngine instance. 44 MLIR_CAPI_EXPORTED void mlirExecutionEngineDestroy(MlirExecutionEngine jit); 45 46 /// Checks whether an execution engine is null. 47 static inline bool mlirExecutionEngineIsNull(MlirExecutionEngine jit) { 48 return !jit.ptr; 49 } 50 51 /// Invoke a native function in the execution engine by name with the arguments 52 /// and result of the invoked function passed as an array of pointers. The 53 /// function must have been tagged with the `llvm.emit_c_interface` attribute. 54 /// Returns a failure if the execution fails for any reason (the function name 55 /// can't be resolved for instance). 56 MLIR_CAPI_EXPORTED MlirLogicalResult mlirExecutionEngineInvokePacked( 57 MlirExecutionEngine jit, MlirStringRef name, void **arguments); 58 59 /// Lookup a native function in the execution engine by name, returns nullptr 60 /// if the name can't be looked-up. 61 MLIR_CAPI_EXPORTED void *mlirExecutionEngineLookup(MlirExecutionEngine jit, 62 MlirStringRef name); 63 64 /// Register a symbol with the jit: this symbol will be accessible to the jitted 65 /// code. 66 MLIR_CAPI_EXPORTED void 67 mlirExecutionEngineRegisterSymbol(MlirExecutionEngine jit, MlirStringRef name, 68 void *sym); 69 70 /// Dump as an object in `fileName`. 71 MLIR_CAPI_EXPORTED void 72 mlirExecutionEngineDumpToObjectFile(MlirExecutionEngine jit, 73 MlirStringRef fileName); 74 75 #ifdef __cplusplus 76 } 77 #endif 78 79 #endif // EXECUTIONENGINE_H 80