[ORC] Add std::tuple support to SimplePackedSerialization.
[llvm-project.git] / llvm / examples / OrcV2Examples / LLJITWithRemoteDebugging / RemoteJITUtils.h
blob2570f90104160434f38f2ad0ffcd90e7c30602d8
1 //===-- RemoteJITUtils.h - Utilities for remote-JITing ----------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Utilities for ExecutorProcessControl-based remote JITing with Orc and
10 // JITLink.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_EXAMPLES_ORCV2EXAMPLES_LLJITWITHREMOTEDEBUGGING_REMOTEJITUTILS_H
15 #define LLVM_EXAMPLES_ORCV2EXAMPLES_LLJITWITHREMOTEDEBUGGING_REMOTEJITUTILS_H
17 #include "llvm/ADT/ArrayRef.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/ADT/Triple.h"
20 #include "llvm/ExecutionEngine/JITSymbol.h"
21 #include "llvm/ExecutionEngine/Orc/Core.h"
22 #include "llvm/ExecutionEngine/Orc/Layer.h"
23 #include "llvm/ExecutionEngine/Orc/ObjectTransformLayer.h"
24 #include "llvm/ExecutionEngine/Orc/Shared/FDRawByteChannel.h"
25 #include "llvm/Support/Error.h"
27 #include <memory>
28 #include <string>
30 #if !defined(_MSC_VER) && !defined(__MINGW32__)
31 #include <unistd.h>
32 #else
33 #include <io.h>
34 #endif
36 namespace llvm {
37 namespace orc {
39 class ChildProcessJITLinkExecutor;
40 class RemoteExecutorProcessControl;
41 class TCPSocketJITLinkExecutor;
43 class JITLinkExecutor {
44 public:
45 using RPCChannel = shared::FDRawByteChannel;
47 /// Create a JITLinkExecutor for the given exectuable on disk.
48 static Expected<std::unique_ptr<ChildProcessJITLinkExecutor>>
49 CreateLocal(std::string ExecutablePath);
51 /// Find the default exectuable on disk and create a JITLinkExecutor for it.
52 static Expected<std::unique_ptr<ChildProcessJITLinkExecutor>>
53 FindLocal(const char *JITArgv0);
55 /// Create a JITLinkExecutor that connects to the given network address
56 /// through a TCP socket. A valid NetworkAddress provides hostname and port,
57 /// e.g. localhost:20000.
58 static Expected<std::unique_ptr<TCPSocketJITLinkExecutor>>
59 ConnectTCPSocket(StringRef NetworkAddress,
60 unique_function<void(Error)> ErrorReporter);
62 // Implement ObjectLinkingLayerCreator
63 Expected<std::unique_ptr<ObjectLayer>> operator()(ExecutionSession &,
64 const Triple &);
66 std::unique_ptr<ExecutionSession> startSession();
67 Error disconnect();
69 Error addDebugSupport(ObjectLayer &ObjLayer);
71 Expected<std::unique_ptr<DefinitionGenerator>>
72 loadDylib(StringRef RemotePath);
74 Expected<int> runAsMain(JITEvaluatedSymbol MainSym,
75 ArrayRef<std::string> Args);
77 virtual ~JITLinkExecutor();
79 protected:
80 std::unique_ptr<RemoteExecutorProcessControl> OwnedEPC;
81 RemoteExecutorProcessControl *EPC{nullptr};
83 JITLinkExecutor();
86 /// JITLinkExecutor that runs in a child process on the local machine.
87 class ChildProcessJITLinkExecutor : public JITLinkExecutor {
88 public:
89 Error launch(unique_function<void(Error)> ErrorReporter);
91 pid_t getPID() const { return ProcessID; }
92 StringRef getPath() const { return ExecutablePath; }
94 private:
95 std::string ExecutablePath;
96 pid_t ProcessID;
98 ChildProcessJITLinkExecutor(std::string ExecutablePath)
99 : ExecutablePath(std::move(ExecutablePath)) {}
101 static std::string defaultPath(const char *HostArgv0, StringRef ExecutorName);
102 friend class JITLinkExecutor;
105 /// JITLinkExecutor connected through a TCP socket.
106 class TCPSocketJITLinkExecutor : public JITLinkExecutor {
107 private:
108 TCPSocketJITLinkExecutor(std::unique_ptr<RemoteExecutorProcessControl> EPC);
110 friend class JITLinkExecutor;
113 } // namespace orc
114 } // namespace llvm
116 #endif