diff options
| author | Lang Hames <lhames@gmail.com> | 2016-11-11 19:42:44 +0000 |
|---|---|---|
| committer | Lang Hames <lhames@gmail.com> | 2016-11-11 19:42:44 +0000 |
| commit | ae1fdddbc4da0cffb219bc6f19b42a9e89f0c3b1 (patch) | |
| tree | 33a93248b3e54f91119ad33f7663bc6b1fda76ee /llvm/tools | |
| parent | da0149dd74980bbe9175009b74f3a37cddec71cd (diff) | |
| download | bcm5719-llvm-ae1fdddbc4da0cffb219bc6f19b42a9e89f0c3b1.tar.gz bcm5719-llvm-ae1fdddbc4da0cffb219bc6f19b42a9e89f0c3b1.zip | |
[ORC] Refactor the ORC RPC utilities to add some new features.
(1) Add support for function key negotiation.
The previous version of the RPC required both sides to maintain the same
enumeration for functions in the API. This means that any version skew between
the client and server would result in communication failure.
With this version of the patch functions (and serializable types) are defined
with string names, and the derived function signature strings are used to
negotiate the actual function keys (which are used for efficient call
serialization). This allows clients to connect to any server that supports a
superset of the API (based on the function signatures it supports).
(2) Add a callAsync primitive.
The callAsync primitive can be used to install a return value handler that will
run as soon as the RPC function's return value is sent back from the remote.
(3) Launch policies for RPC function handlers.
The new addHandler method, which installs handlers for RPC functions, takes two
arguments: (1) the handler itself, and (2) an optional "launch policy". When the
RPC function is called, the launch policy (if present) is invoked to actually
launch the handler. This allows the handler to be spawned on a background
thread, or added to a work list. If no launch policy is used, the handler is run
on the server thread itself. This should only be used for short-running
handlers, or entirely synchronous RPC APIs.
(4) Zero cost cross type serialization.
You can now define serialization from any type to a different "wire" type. For
example, this allows you to call an RPC function that's defined to take a
std::string while passing a StringRef argument. If a serializer from StringRef
to std::string has been defined for the channel type this will be used to
serialize the argument without having to construct a std::string instance.
This allows buffer reference types to be used as arguments to RPC calls without
requiring a copy of the buffer to be made.
llvm-svn: 286620
Diffstat (limited to 'llvm/tools')
| -rw-r--r-- | llvm/tools/lli/ChildTarget/ChildTarget.cpp | 19 | ||||
| -rw-r--r-- | llvm/tools/lli/RemoteJITUtils.h | 11 | ||||
| -rw-r--r-- | llvm/tools/lli/lli.cpp | 18 |
3 files changed, 19 insertions, 29 deletions
diff --git a/llvm/tools/lli/ChildTarget/ChildTarget.cpp b/llvm/tools/lli/ChildTarget/ChildTarget.cpp index f6d2413655e..77b1d47a946 100644 --- a/llvm/tools/lli/ChildTarget/ChildTarget.cpp +++ b/llvm/tools/lli/ChildTarget/ChildTarget.cpp @@ -53,23 +53,12 @@ int main(int argc, char *argv[]) { RTDyldMemoryManager::deregisterEHFramesInProcess(Addr, Size); }; - FDRPCChannel Channel(InFD, OutFD); - typedef remote::OrcRemoteTargetServer<FDRPCChannel, HostOrcArch> JITServer; + FDRawChannel Channel(InFD, OutFD); + typedef remote::OrcRemoteTargetServer<FDRawChannel, HostOrcArch> JITServer; JITServer Server(Channel, SymbolLookup, RegisterEHFrames, DeregisterEHFrames); - while (1) { - uint32_t RawId; - ExitOnErr(Server.startReceivingFunction(Channel, RawId)); - auto Id = static_cast<JITServer::JITFuncId>(RawId); - switch (Id) { - case JITServer::TerminateSessionId: - ExitOnErr(Server.handleTerminateSession()); - return 0; - default: - ExitOnErr(Server.handleKnownFunction(Id)); - break; - } - } + while (!Server.receivedTerminate()) + ExitOnErr(Server.handleOne()); close(InFD); close(OutFD); diff --git a/llvm/tools/lli/RemoteJITUtils.h b/llvm/tools/lli/RemoteJITUtils.h index d47716cb880..89a51420256 100644 --- a/llvm/tools/lli/RemoteJITUtils.h +++ b/llvm/tools/lli/RemoteJITUtils.h @@ -14,7 +14,7 @@ #ifndef LLVM_TOOLS_LLI_REMOTEJITUTILS_H #define LLVM_TOOLS_LLI_REMOTEJITUTILS_H -#include "llvm/ExecutionEngine/Orc/RPCByteChannel.h" +#include "llvm/ExecutionEngine/Orc/RawByteChannel.h" #include "llvm/ExecutionEngine/RTDyldMemoryManager.h" #include <mutex> @@ -25,9 +25,9 @@ #endif /// RPC channel that reads from and writes from file descriptors. -class FDRPCChannel final : public llvm::orc::remote::RPCByteChannel { +class FDRawChannel final : public llvm::orc::rpc::RawByteChannel { public: - FDRPCChannel(int InFD, int OutFD) : InFD(InFD), OutFD(OutFD) {} + FDRawChannel(int InFD, int OutFD) : InFD(InFD), OutFD(OutFD) {} llvm::Error readBytes(char *Dst, unsigned Size) override { assert(Dst && "Attempt to read into null."); @@ -72,11 +72,12 @@ private: }; // launch the remote process (see lli.cpp) and return a channel to it. -std::unique_ptr<FDRPCChannel> launchRemote(); +std::unique_ptr<FDRawChannel> launchRemote(); namespace llvm { -// ForwardingMM - Adapter to connect MCJIT to Orc's Remote memory manager. +// ForwardingMM - Adapter to connect MCJIT to Orc's Remote8 +// memory manager. class ForwardingMemoryManager : public llvm::RTDyldMemoryManager { public: void setMemMgr(std::unique_ptr<RuntimeDyld::MemoryManager> MemMgr) { diff --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp index 9dbe658beff..836a94037d7 100644 --- a/llvm/tools/lli/lli.cpp +++ b/llvm/tools/lli/lli.cpp @@ -654,20 +654,20 @@ int main(int argc, char **argv, char * const *envp) { // MCJIT itself. FIXME. // Lanch the remote process and get a channel to it. - std::unique_ptr<FDRPCChannel> C = launchRemote(); + std::unique_ptr<FDRawChannel> C = launchRemote(); if (!C) { errs() << "Failed to launch remote JIT.\n"; exit(1); } // Create a remote target client running over the channel. - typedef orc::remote::OrcRemoteTargetClient<orc::remote::RPCByteChannel> + typedef orc::remote::OrcRemoteTargetClient<orc::rpc::RawByteChannel> MyRemote; - MyRemote R = ExitOnErr(MyRemote::Create(*C)); + auto R = ExitOnErr(MyRemote::Create(*C)); // Create a remote memory manager. std::unique_ptr<MyRemote::RCMemoryManager> RemoteMM; - ExitOnErr(R.createRemoteMemoryManager(RemoteMM)); + ExitOnErr(R->createRemoteMemoryManager(RemoteMM)); // Forward MCJIT's memory manager calls to the remote memory manager. static_cast<ForwardingMemoryManager*>(RTDyldMM)->setMemMgr( @@ -678,7 +678,7 @@ int main(int argc, char **argv, char * const *envp) { orc::createLambdaResolver( [](const std::string &Name) { return nullptr; }, [&](const std::string &Name) { - if (auto Addr = ExitOnErr(R.getSymbolAddress(Name))) + if (auto Addr = ExitOnErr(R->getSymbolAddress(Name))) return JITSymbol(Addr, JITSymbolFlags::Exported); return JITSymbol(nullptr); } @@ -691,7 +691,7 @@ int main(int argc, char **argv, char * const *envp) { EE->finalizeObject(); DEBUG(dbgs() << "Executing '" << EntryFn->getName() << "' at 0x" << format("%llx", Entry) << "\n"); - Result = ExitOnErr(R.callIntVoid(Entry)); + Result = ExitOnErr(R->callIntVoid(Entry)); // Like static constructors, the remote target MCJIT support doesn't handle // this yet. It could. FIXME. @@ -702,13 +702,13 @@ int main(int argc, char **argv, char * const *envp) { EE.reset(); // Signal the remote target that we're done JITing. - ExitOnErr(R.terminateSession()); + ExitOnErr(R->terminateSession()); } return Result; } -std::unique_ptr<FDRPCChannel> launchRemote() { +std::unique_ptr<FDRawChannel> launchRemote() { #ifndef LLVM_ON_UNIX llvm_unreachable("launchRemote not supported on non-Unix platforms"); #else @@ -758,6 +758,6 @@ std::unique_ptr<FDRPCChannel> launchRemote() { close(PipeFD[1][1]); // Return an RPC channel connected to our end of the pipes. - return llvm::make_unique<FDRPCChannel>(PipeFD[1][0], PipeFD[0][1]); + return llvm::make_unique<FDRawChannel>(PipeFD[1][0], PipeFD[0][1]); #endif } |

