forked from OSchip/llvm-project
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:
parent
b588d58c5f
commit
629f5b7fcb
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue