Skip to content

Commit eed19c8

Browse files
committed
[ORC] Move file-descriptor based raw byte channel into a public header.
This will enable re-use in other llvm tools.
1 parent 989d8dc commit eed19c8

File tree

7 files changed

+98
-63
lines changed

7 files changed

+98
-63
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//===- FDRawByteChannel.h - File descriptor based byte-channel -*- 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+
// File descriptor based RawByteChannel.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef LLVM_EXECUTIONENGINE_ORC_RPC_FDRAWBYTECHANNEL_H
14+
#define LLVM_EXECUTIONENGINE_ORC_RPC_FDRAWBYTECHANNEL_H
15+
16+
#include "llvm/ExecutionEngine/Orc/RPC/RawByteChannel.h"
17+
18+
#if !defined(_MSC_VER) && !defined(__MINGW32__)
19+
#include <unistd.h>
20+
#else
21+
#include <io.h>
22+
#endif
23+
24+
namespace llvm {
25+
namespace orc {
26+
namespace rpc {
27+
28+
/// RPC channel that reads from and writes from file descriptors.
29+
class FDRawByteChannel final : public RawByteChannel {
30+
public:
31+
FDRawByteChannel(int InFD, int OutFD) : InFD(InFD), OutFD(OutFD) {}
32+
33+
llvm::Error readBytes(char *Dst, unsigned Size) override {
34+
assert(Dst && "Attempt to read into null.");
35+
ssize_t Completed = 0;
36+
while (Completed < static_cast<ssize_t>(Size)) {
37+
ssize_t Read = ::read(InFD, Dst + Completed, Size - Completed);
38+
if (Read <= 0) {
39+
auto ErrNo = errno;
40+
if (ErrNo == EAGAIN || ErrNo == EINTR)
41+
continue;
42+
else
43+
return llvm::errorCodeToError(
44+
std::error_code(errno, std::generic_category()));
45+
}
46+
Completed += Read;
47+
}
48+
return llvm::Error::success();
49+
}
50+
51+
llvm::Error appendBytes(const char *Src, unsigned Size) override {
52+
assert(Src && "Attempt to append from null.");
53+
ssize_t Completed = 0;
54+
while (Completed < static_cast<ssize_t>(Size)) {
55+
ssize_t Written = ::write(OutFD, Src + Completed, Size - Completed);
56+
if (Written < 0) {
57+
auto ErrNo = errno;
58+
if (ErrNo == EAGAIN || ErrNo == EINTR)
59+
continue;
60+
else
61+
return llvm::errorCodeToError(
62+
std::error_code(errno, std::generic_category()));
63+
}
64+
Completed += Written;
65+
}
66+
return llvm::Error::success();
67+
}
68+
69+
llvm::Error send() override { return llvm::Error::success(); }
70+
71+
private:
72+
int InFD, OutFD;
73+
};
74+
75+
} // namespace rpc
76+
} // namespace orc
77+
} // namespace llvm
78+
79+
#endif // LLVM_EXECUTIONENGINE_ORC_RPC_FDRAWBYTECHANNEL_H

llvm/include/llvm/ExecutionEngine/Orc/RPC/RPCSerialization.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_EXECUTIONENGINE_ORC_RPCSERIALIZATION_H
10-
#define LLVM_EXECUTIONENGINE_ORC_RPCSERIALIZATION_H
9+
#ifndef LLVM_EXECUTIONENGINE_ORC_RPC_RPCSERIALIZATION_H
10+
#define LLVM_EXECUTIONENGINE_ORC_RPC_RPCSERIALIZATION_H
1111

1212
#include "llvm/ExecutionEngine/Orc/OrcError.h"
1313
#include "llvm/Support/thread.h"
@@ -699,4 +699,4 @@ class SerializationTraits<ChannelT, std::map<K, V>, std::map<K2, V2>> {
699699
} // end namespace orc
700700
} // end namespace llvm
701701

702-
#endif // LLVM_EXECUTIONENGINE_ORC_RPCSERIALIZATION_H
702+
#endif // LLVM_EXECUTIONENGINE_ORC_RPC_RPCSERIALIZATION_H

llvm/include/llvm/ExecutionEngine/Orc/RPC/RPCUtils.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17-
#ifndef LLVM_EXECUTIONENGINE_ORC_RPCUTILS_H
18-
#define LLVM_EXECUTIONENGINE_ORC_RPCUTILS_H
17+
#ifndef LLVM_EXECUTIONENGINE_ORC_RPC_RPCUTILS_H
18+
#define LLVM_EXECUTIONENGINE_ORC_RPC_RPCUTILS_H
1919

2020
#include <map>
2121
#include <thread>
@@ -1684,4 +1684,4 @@ class APICalls<APICalls<InnerFuncs...>, Funcs...> {
16841684
} // end namespace orc
16851685
} // end namespace llvm
16861686

1687-
#endif
1687+
#endif // LLVM_EXECUTIONENGINE_ORC_RPC_RPCUTILS_H

llvm/include/llvm/ExecutionEngine/Orc/RPC/RawByteChannel.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_EXECUTIONENGINE_ORC_RAWBYTECHANNEL_H
10-
#define LLVM_EXECUTIONENGINE_ORC_RAWBYTECHANNEL_H
9+
#ifndef LLVM_EXECUTIONENGINE_ORC_RPC_RAWBYTECHANNEL_H
10+
#define LLVM_EXECUTIONENGINE_ORC_RPC_RAWBYTECHANNEL_H
1111

1212
#include "llvm/ADT/StringRef.h"
1313
#include "llvm/ExecutionEngine/Orc/RPC/RPCSerialization.h"
@@ -181,4 +181,4 @@ class SerializationTraits<
181181
} // end namespace orc
182182
} // end namespace llvm
183183

184-
#endif // LLVM_EXECUTIONENGINE_ORC_RAWBYTECHANNEL_H
184+
#endif // LLVM_EXECUTIONENGINE_ORC_RPC_RAWBYTECHANNEL_H

llvm/tools/lli/ChildTarget/ChildTarget.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "llvm/ExecutionEngine/Orc/OrcABISupport.h"
22
#include "llvm/ExecutionEngine/Orc/OrcRemoteTargetServer.h"
3+
#include "llvm/ExecutionEngine/Orc/RPC/FDRawByteChannel.h"
34
#include "llvm/Support/Debug.h"
45
#include "llvm/Support/DynamicLibrary.h"
56
#include "llvm/Support/Process.h"
@@ -53,8 +54,9 @@ int main(int argc, char *argv[]) {
5354
RTDyldMemoryManager::deregisterEHFramesInProcess(Addr, Size);
5455
};
5556

56-
FDRawChannel Channel(InFD, OutFD);
57-
typedef remote::OrcRemoteTargetServer<FDRawChannel, HostOrcArch> JITServer;
57+
rpc::FDRawByteChannel Channel(InFD, OutFD);
58+
typedef remote::OrcRemoteTargetServer<rpc::FDRawByteChannel, HostOrcArch>
59+
JITServer;
5860
JITServer Server(Channel, SymbolLookup, RegisterEHFrames, DeregisterEHFrames);
5961

6062
while (!Server.receivedTerminate())

llvm/tools/lli/RemoteJITUtils.h

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#ifndef LLVM_TOOLS_LLI_REMOTEJITUTILS_H
1414
#define LLVM_TOOLS_LLI_REMOTEJITUTILS_H
1515

16-
#include "llvm/ExecutionEngine/Orc/RPC/RawByteChannel.h"
16+
#include "llvm/ExecutionEngine/Orc/RPC/FDRawByteChannel.h"
1717
#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
1818
#include <mutex>
1919

@@ -23,55 +23,8 @@
2323
#include <io.h>
2424
#endif
2525

26-
/// RPC channel that reads from and writes from file descriptors.
27-
class FDRawChannel final : public llvm::orc::rpc::RawByteChannel {
28-
public:
29-
FDRawChannel(int InFD, int OutFD) : InFD(InFD), OutFD(OutFD) {}
30-
31-
llvm::Error readBytes(char *Dst, unsigned Size) override {
32-
assert(Dst && "Attempt to read into null.");
33-
ssize_t Completed = 0;
34-
while (Completed < static_cast<ssize_t>(Size)) {
35-
ssize_t Read = ::read(InFD, Dst + Completed, Size - Completed);
36-
if (Read <= 0) {
37-
auto ErrNo = errno;
38-
if (ErrNo == EAGAIN || ErrNo == EINTR)
39-
continue;
40-
else
41-
return llvm::errorCodeToError(
42-
std::error_code(errno, std::generic_category()));
43-
}
44-
Completed += Read;
45-
}
46-
return llvm::Error::success();
47-
}
48-
49-
llvm::Error appendBytes(const char *Src, unsigned Size) override {
50-
assert(Src && "Attempt to append from null.");
51-
ssize_t Completed = 0;
52-
while (Completed < static_cast<ssize_t>(Size)) {
53-
ssize_t Written = ::write(OutFD, Src + Completed, Size - Completed);
54-
if (Written < 0) {
55-
auto ErrNo = errno;
56-
if (ErrNo == EAGAIN || ErrNo == EINTR)
57-
continue;
58-
else
59-
return llvm::errorCodeToError(
60-
std::error_code(errno, std::generic_category()));
61-
}
62-
Completed += Written;
63-
}
64-
return llvm::Error::success();
65-
}
66-
67-
llvm::Error send() override { return llvm::Error::success(); }
68-
69-
private:
70-
int InFD, OutFD;
71-
};
72-
7326
// launch the remote process (see lli.cpp) and return a channel to it.
74-
std::unique_ptr<FDRawChannel> launchRemote();
27+
std::unique_ptr<llvm::orc::rpc::FDRawByteChannel> launchRemote();
7528

7629
namespace llvm {
7730

llvm/tools/lli/lli.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ int main(int argc, char **argv, char * const *envp) {
674674
// MCJIT itself. FIXME.
675675

676676
// Lanch the remote process and get a channel to it.
677-
std::unique_ptr<FDRawChannel> C = launchRemote();
677+
std::unique_ptr<orc::rpc::FDRawByteChannel> C = launchRemote();
678678
if (!C) {
679679
WithColor::error(errs(), argv[0]) << "failed to launch remote JIT.\n";
680680
exit(1);
@@ -1026,7 +1026,7 @@ void disallowOrcOptions() {
10261026
}
10271027
}
10281028

1029-
std::unique_ptr<FDRawChannel> launchRemote() {
1029+
std::unique_ptr<orc::rpc::FDRawByteChannel> launchRemote() {
10301030
#ifndef LLVM_ON_UNIX
10311031
llvm_unreachable("launchRemote not supported on non-Unix platforms");
10321032
#else
@@ -1076,6 +1076,7 @@ std::unique_ptr<FDRawChannel> launchRemote() {
10761076
close(PipeFD[1][1]);
10771077

10781078
// Return an RPC channel connected to our end of the pipes.
1079-
return std::make_unique<FDRawChannel>(PipeFD[1][0], PipeFD[0][1]);
1079+
return std::make_unique<orc::rpc::FDRawByteChannel>(PipeFD[1][0],
1080+
PipeFD[0][1]);
10801081
#endif
10811082
}

0 commit comments

Comments
 (0)