1 //===-- RemoteJITUtils.h - Utilities for remote-JITing ----------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // Utilities for ExecutorProcessControl-based remote JITing with Orc and
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"
30 #if !defined(_MSC_VER) && !defined(__MINGW32__)
39 class ChildProcessJITLinkExecutor
;
40 class RemoteExecutorProcessControl
;
41 class TCPSocketJITLinkExecutor
;
43 class JITLinkExecutor
{
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
&,
66 std::unique_ptr
<ExecutionSession
> startSession();
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();
80 std::unique_ptr
<RemoteExecutorProcessControl
> OwnedEPC
;
81 RemoteExecutorProcessControl
*EPC
{nullptr};
86 /// JITLinkExecutor that runs in a child process on the local machine.
87 class ChildProcessJITLinkExecutor
: public JITLinkExecutor
{
89 Error
launch(unique_function
<void(Error
)> ErrorReporter
);
91 pid_t
getPID() const { return ProcessID
; }
92 StringRef
getPath() const { return ExecutablePath
; }
95 std::string ExecutablePath
;
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
{
108 TCPSocketJITLinkExecutor(std::unique_ptr
<RemoteExecutorProcessControl
> EPC
);
110 friend class JITLinkExecutor
;