Add a simple arity-agnostic invocation of JIT-compiled functions.

This is useful to call generic function with unspecified number of arguments
e.g. when interfacing with ML frameworks.

PiperOrigin-RevId: 230974736
This commit is contained in:
Nicolas Vasilache 2019-01-25 14:57:30 -08:00 committed by jpienaar
parent b588d58c5f
commit 629f5b7fcb
2 changed files with 17 additions and 0 deletions

View File

@ -67,6 +67,11 @@ public:
template <typename... Args>
llvm::Error invoke(StringRef name, Args &... args);
/// Invokes the function with the given name passing it the list of arguments
/// as a list of opaque pointers. This is the arity-agnostic equivalent of
/// the templated `invoke`.
llvm::Error invoke(StringRef name, MutableArrayRef<void *> args);
private:
// Private implementation of the JIT (PIMPL)
std::unique_ptr<impl::OrcJIT> jit;

View File

@ -295,3 +295,15 @@ Expected<void (*)(void **)> ExecutionEngine::lookup(StringRef name) const {
return make_string_error("looked up function is null");
return fptr;
}
llvm::Error ExecutionEngine::invoke(StringRef name,
MutableArrayRef<void *> args) {
auto expectedFPtr = lookup(name);
if (!expectedFPtr)
return expectedFPtr.takeError();
auto fptr = *expectedFPtr;
(*fptr)(args.data());
return llvm::Error::success();
}