summaryrefslogtreecommitdiffstats
path: root/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter5/RemoteJITUtils.h
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2016-05-30 00:09:26 +0000
committerLang Hames <lhames@gmail.com>2016-05-30 00:09:26 +0000
commita243ba9cad0621d9ca3be4bceddbc58f02a10ca0 (patch)
treea4c46ed937421c4f63d9f5b97d7e6bbb88605369 /llvm/examples/Kaleidoscope/BuildingAJIT/Chapter5/RemoteJITUtils.h
parented58207c463b762da9bca22273ac2942b216b785 (diff)
downloadbcm5719-llvm-a243ba9cad0621d9ca3be4bceddbc58f02a10ca0.tar.gz
bcm5719-llvm-a243ba9cad0621d9ca3be4bceddbc58f02a10ca0.zip
[Kaleidoscope][BuildingAJIT] Add code for Chapter 5 - remote JITing.
This chapter demonstrates lazily JITing from ASTs with the expressions being executed on a remote machine via a TCP connection. It needs some polish, but is substantially complete. Currently x86-64 SysV ABI (Darwin and Linux) only, but other architectures can be supported by changing the server code to use alternative ABI support classes from llvm/include/llvm/ExecutionEngine/Orc/OrcABISupport.h. llvm-svn: 271193
Diffstat (limited to 'llvm/examples/Kaleidoscope/BuildingAJIT/Chapter5/RemoteJITUtils.h')
-rw-r--r--llvm/examples/Kaleidoscope/BuildingAJIT/Chapter5/RemoteJITUtils.h74
1 files changed, 74 insertions, 0 deletions
diff --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter5/RemoteJITUtils.h b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter5/RemoteJITUtils.h
new file mode 100644
index 00000000000..869d0a7ef39
--- /dev/null
+++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter5/RemoteJITUtils.h
@@ -0,0 +1,74 @@
+//===-- RemoteJITUtils.h - Utilities for remote-JITing with LLI -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Utilities for remote-JITing with LLI.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TOOLS_LLI_REMOTEJITUTILS_H
+#define LLVM_TOOLS_LLI_REMOTEJITUTILS_H
+
+#include "llvm/ExecutionEngine/Orc/RPCChannel.h"
+#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
+#include <mutex>
+
+#if !defined(_MSC_VER) && !defined(__MINGW32__)
+#include <unistd.h>
+#else
+#include <io.h>
+#endif
+
+/// RPC channel that reads from and writes from file descriptors.
+class FDRPCChannel final : public llvm::orc::remote::RPCChannel {
+public:
+ FDRPCChannel(int InFD, int OutFD) : InFD(InFD), OutFD(OutFD) {}
+
+ llvm::Error readBytes(char *Dst, unsigned Size) override {
+ assert(Dst && "Attempt to read into null.");
+ ssize_t Completed = 0;
+ while (Completed < static_cast<ssize_t>(Size)) {
+ ssize_t Read = ::read(InFD, Dst + Completed, Size - Completed);
+ if (Read <= 0) {
+ auto ErrNo = errno;
+ if (ErrNo == EAGAIN || ErrNo == EINTR)
+ continue;
+ else
+ return llvm::errorCodeToError(
+ std::error_code(errno, std::generic_category()));
+ }
+ Completed += Read;
+ }
+ return llvm::Error::success();
+ }
+
+ llvm::Error appendBytes(const char *Src, unsigned Size) override {
+ assert(Src && "Attempt to append from null.");
+ ssize_t Completed = 0;
+ while (Completed < static_cast<ssize_t>(Size)) {
+ ssize_t Written = ::write(OutFD, Src + Completed, Size - Completed);
+ if (Written < 0) {
+ auto ErrNo = errno;
+ if (ErrNo == EAGAIN || ErrNo == EINTR)
+ continue;
+ else
+ return llvm::errorCodeToError(
+ std::error_code(errno, std::generic_category()));
+ }
+ Completed += Written;
+ }
+ return llvm::Error::success();
+ }
+
+ llvm::Error send() override { return llvm::Error::success(); }
+
+private:
+ int InFD, OutFD;
+};
+
+#endif
OpenPOWER on IntegriCloud