MLIR_CAPI_EXPORTED MlirLogicalResult mlirExecutionEngineInvokePacked(
MlirExecutionEngine jit, MlirStringRef name, void **arguments);
+/// Lookup the wrapper of the native function in the execution engine with the
+/// given name, returns nullptr if the function can't be looked-up.
+MLIR_CAPI_EXPORTED void *
+mlirExecutionEngineLookupPacked(MlirExecutionEngine jit, MlirStringRef name);
+
/// Lookup a native function in the execution engine by name, returns nullptr
/// if the name can't be looked-up.
MLIR_CAPI_EXPORTED void *mlirExecutionEngineLookup(MlirExecutionEngine jit,
bool enableGDBNotificationListener = true,
bool enablePerfNotificationListener = true);
- /// Looks up a packed-argument function with the given name and returns a
- /// pointer to it. Propagates errors in case of failure.
- llvm::Expected<void (*)(void **)> lookup(StringRef name) const;
+ /// Looks up a packed-argument function wrapping the function with the given
+ /// name and returns a pointer to it. Propagates errors in case of failure.
+ llvm::Expected<void (*)(void **)> lookupPacked(StringRef name) const;
+
+ /// Looks up the original function with the given name and returns a
+ /// pointer to it. This is not necesarily a packed function. Propagates
+ /// errors in case of failure.
+ llvm::Expected<void *> lookup(StringRef name) const;
/// Invokes the function with the given name passing it the list of opaque
/// pointers to the actual arguments.
.def(
"raw_lookup",
[](PyExecutionEngine &executionEngine, const std::string &func) {
- auto *res = mlirExecutionEngineLookup(
+ auto *res = mlirExecutionEngineLookupPacked(
executionEngine.get(),
mlirStringRefCreate(func.c_str(), func.size()));
return reinterpret_cast<uintptr_t>(res);
return wrap(success());
}
+extern "C" void *mlirExecutionEngineLookupPacked(MlirExecutionEngine jit,
+ MlirStringRef name) {
+ auto expectedFPtr = unwrap(jit)->lookupPacked(unwrap(name));
+ if (!expectedFPtr)
+ return nullptr;
+ return reinterpret_cast<void *>(*expectedFPtr);
+}
+
extern "C" void *mlirExecutionEngineLookup(MlirExecutionEngine jit,
MlirStringRef name) {
auto expectedFPtr = unwrap(jit)->lookup(unwrap(name));
return std::move(engine);
}
-Expected<void (*)(void **)> ExecutionEngine::lookup(StringRef name) const {
- auto expectedSymbol = jit->lookup(makePackedFunctionName(name));
+Expected<void (*)(void **)>
+ExecutionEngine::lookupPacked(StringRef name) const {
+ auto result = lookup(makePackedFunctionName(name));
+ if (!result)
+ return result.takeError();
+ return reinterpret_cast<void (*)(void **)>(result.get());
+}
+
+Expected<void *> ExecutionEngine::lookup(StringRef name) const {
+ auto expectedSymbol = jit->lookup(name);
// JIT lookup may return an Error referring to strings stored internally by
// the JIT. If the Error outlives the ExecutionEngine, it would want have a
}
auto rawFPtr = expectedSymbol->getAddress();
- auto fptr = reinterpret_cast<void (*)(void **)>(rawFPtr);
+ auto fptr = reinterpret_cast<void *>(rawFPtr);
if (!fptr)
return make_string_error("looked up function is null");
return fptr;
Error ExecutionEngine::invokePacked(StringRef name,
MutableArrayRef<void *> args) {
- auto expectedFPtr = lookup(name);
+ auto expectedFPtr = lookupPacked(name);
if (!expectedFPtr)
return expectedFPtr.takeError();
auto fptr = *expectedFPtr;
auto engine = std::move(*expectedEngine);
engine->registerSymbols(runtimeSymbolMap);
- auto expectedFPtr = engine->lookup(entryPoint);
+ auto expectedFPtr = engine->lookupPacked(entryPoint);
if (!expectedFPtr)
return expectedFPtr.takeError();