[PowerPC] Make AddrSpaceCast noop
[llvm-core.git] / tools / lli / RemoteJITUtils.h
blob944881070c7034e2267a802d4ca82bef45a450a7
1 //===-- RemoteJITUtils.h - Utilities for remote-JITing with LLI -*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Utilities for remote-JITing with LLI.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_TOOLS_LLI_REMOTEJITUTILS_H
15 #define LLVM_TOOLS_LLI_REMOTEJITUTILS_H
17 #include "llvm/ExecutionEngine/Orc/RawByteChannel.h"
18 #include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
19 #include <mutex>
21 #if !defined(_MSC_VER) && !defined(__MINGW32__)
22 #include <unistd.h>
23 #else
24 #include <io.h>
25 #endif
27 /// RPC channel that reads from and writes from file descriptors.
28 class FDRawChannel final : public llvm::orc::rpc::RawByteChannel {
29 public:
30 FDRawChannel(int InFD, int OutFD) : InFD(InFD), OutFD(OutFD) {}
32 llvm::Error readBytes(char *Dst, unsigned Size) override {
33 assert(Dst && "Attempt to read into null.");
34 ssize_t Completed = 0;
35 while (Completed < static_cast<ssize_t>(Size)) {
36 ssize_t Read = ::read(InFD, Dst + Completed, Size - Completed);
37 if (Read <= 0) {
38 auto ErrNo = errno;
39 if (ErrNo == EAGAIN || ErrNo == EINTR)
40 continue;
41 else
42 return llvm::errorCodeToError(
43 std::error_code(errno, std::generic_category()));
45 Completed += Read;
47 return llvm::Error::success();
50 llvm::Error appendBytes(const char *Src, unsigned Size) override {
51 assert(Src && "Attempt to append from null.");
52 ssize_t Completed = 0;
53 while (Completed < static_cast<ssize_t>(Size)) {
54 ssize_t Written = ::write(OutFD, Src + Completed, Size - Completed);
55 if (Written < 0) {
56 auto ErrNo = errno;
57 if (ErrNo == EAGAIN || ErrNo == EINTR)
58 continue;
59 else
60 return llvm::errorCodeToError(
61 std::error_code(errno, std::generic_category()));
63 Completed += Written;
65 return llvm::Error::success();
68 llvm::Error send() override { return llvm::Error::success(); }
70 private:
71 int InFD, OutFD;
74 // launch the remote process (see lli.cpp) and return a channel to it.
75 std::unique_ptr<FDRawChannel> launchRemote();
77 namespace llvm {
79 // ForwardingMM - Adapter to connect MCJIT to Orc's Remote8
80 // memory manager.
81 class ForwardingMemoryManager : public llvm::RTDyldMemoryManager {
82 public:
83 void setMemMgr(std::unique_ptr<RuntimeDyld::MemoryManager> MemMgr) {
84 this->MemMgr = std::move(MemMgr);
87 void setResolver(std::shared_ptr<LegacyJITSymbolResolver> Resolver) {
88 this->Resolver = std::move(Resolver);
91 uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
92 unsigned SectionID,
93 StringRef SectionName) override {
94 return MemMgr->allocateCodeSection(Size, Alignment, SectionID, SectionName);
97 uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
98 unsigned SectionID, StringRef SectionName,
99 bool IsReadOnly) override {
100 return MemMgr->allocateDataSection(Size, Alignment, SectionID, SectionName,
101 IsReadOnly);
104 void reserveAllocationSpace(uintptr_t CodeSize, uint32_t CodeAlign,
105 uintptr_t RODataSize, uint32_t RODataAlign,
106 uintptr_t RWDataSize,
107 uint32_t RWDataAlign) override {
108 MemMgr->reserveAllocationSpace(CodeSize, CodeAlign, RODataSize, RODataAlign,
109 RWDataSize, RWDataAlign);
112 bool needsToReserveAllocationSpace() override {
113 return MemMgr->needsToReserveAllocationSpace();
116 void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr,
117 size_t Size) override {
118 MemMgr->registerEHFrames(Addr, LoadAddr, Size);
121 void deregisterEHFrames() override {
122 MemMgr->deregisterEHFrames();
125 bool finalizeMemory(std::string *ErrMsg = nullptr) override {
126 return MemMgr->finalizeMemory(ErrMsg);
129 void notifyObjectLoaded(RuntimeDyld &RTDyld,
130 const object::ObjectFile &Obj) override {
131 MemMgr->notifyObjectLoaded(RTDyld, Obj);
134 // Don't hide the sibling notifyObjectLoaded from RTDyldMemoryManager.
135 using RTDyldMemoryManager::notifyObjectLoaded;
137 JITSymbol findSymbol(const std::string &Name) override {
138 return Resolver->findSymbol(Name);
141 JITSymbol
142 findSymbolInLogicalDylib(const std::string &Name) override {
143 return Resolver->findSymbolInLogicalDylib(Name);
146 private:
147 std::unique_ptr<RuntimeDyld::MemoryManager> MemMgr;
148 std::shared_ptr<LegacyJITSymbolResolver> Resolver;
152 #endif