freebsd-dev/contrib/llvm/tools/lli/RemoteTargetExternal.cpp
Dimitry Andric f785676f2a Upgrade our copy of llvm/clang to 3.4 release. This version supports
all of the features in the current working draft of the upcoming C++
standard, provisionally named C++1y.

The code generator's performance is greatly increased, and the loop
auto-vectorizer is now enabled at -Os and -O2 in addition to -O3.  The
PowerPC backend has made several major improvements to code generation
quality and compile time, and the X86, SPARC, ARM32, Aarch64 and SystemZ
backends have all seen major feature work.

Release notes for llvm and clang can be found here:
<http://llvm.org/releases/3.4/docs/ReleaseNotes.html>
<http://llvm.org/releases/3.4/tools/clang/docs/ReleaseNotes.html>

MFC after:	1 month
2014-02-16 19:44:07 +00:00

163 lines
4.7 KiB
C++

//===---- RemoteTargetExternal.cpp - LLVM out-of-process JIT execution ----===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Implementation of the RemoteTargetExternal class which executes JITed code
// in a separate process from where it was built.
//
//===----------------------------------------------------------------------===//
#include "llvm/Config/config.h"
#include "RemoteTarget.h"
#include "RemoteTargetExternal.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/Memory.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/raw_ostream.h"
#include <string>
using namespace llvm;
bool RemoteTargetExternal::allocateSpace(size_t Size, unsigned Alignment,
uint64_t &Address) {
SendAllocateSpace(Alignment, Size);
Receive(LLI_AllocationResult, Address);
return false;
}
bool RemoteTargetExternal::loadData(uint64_t Address, const void *Data, size_t Size) {
SendLoadSection(Address, Data, (uint32_t)Size, false);
Receive(LLI_LoadComplete);
return false;
}
bool RemoteTargetExternal::loadCode(uint64_t Address, const void *Data, size_t Size) {
SendLoadSection(Address, Data, (uint32_t)Size, true);
Receive(LLI_LoadComplete);
return false;
}
bool RemoteTargetExternal::executeCode(uint64_t Address, int &RetVal) {
SendExecute(Address);
Receive(LLI_ExecutionResult, RetVal);
return false;
}
void RemoteTargetExternal::stop() {
SendTerminate();
Wait();
}
void RemoteTargetExternal::SendAllocateSpace(uint32_t Alignment, uint32_t Size) {
int rc;
uint32_t MsgType = (uint32_t)LLI_AllocateSpace;
rc = WriteBytes(&MsgType, 4);
assert(rc == 4 && "Error writing message type.");
uint32_t DataSize = 8;
rc = WriteBytes(&DataSize, 4);
assert(rc == 4 && "Error writing data size.");
rc = WriteBytes(&Alignment, 4);
assert(rc == 4 && "Error writing alignment data.");
rc = WriteBytes(&Size, 4);
assert(rc == 4 && "Error writing size data.");
}
void RemoteTargetExternal::SendLoadSection(uint64_t Addr,
const void *Data,
uint32_t Size,
bool IsCode) {
int rc;
uint32_t MsgType = IsCode ? LLI_LoadCodeSection : LLI_LoadDataSection;
rc = WriteBytes(&MsgType, 4);
assert(rc == 4 && "Error writing message type.");
uint32_t DataSize = Size + 8;
rc = WriteBytes(&DataSize, 4);
assert(rc == 4 && "Error writing data size.");
rc = WriteBytes(&Addr, 8);
assert(rc == 8 && "Error writing data.");
rc = WriteBytes(Data, Size);
assert(rc == (int)Size && "Error writing data.");
}
void RemoteTargetExternal::SendExecute(uint64_t Addr) {
int rc;
uint32_t MsgType = (uint32_t)LLI_Execute;
rc = WriteBytes(&MsgType, 4);
assert(rc == 4 && "Error writing message type.");
uint32_t DataSize = 8;
rc = WriteBytes(&DataSize, 4);
assert(rc == 4 && "Error writing data size.");
rc = WriteBytes(&Addr, 8);
assert(rc == 8 && "Error writing data.");
}
void RemoteTargetExternal::SendTerminate() {
int rc;
uint32_t MsgType = (uint32_t)LLI_Terminate;
rc = WriteBytes(&MsgType, 4);
assert(rc == 4 && "Error writing message type.");
// No data or data size is sent with Terminate
}
void RemoteTargetExternal::Receive(LLIMessageType ExpectedMsgType) {
int rc;
uint32_t MsgType;
rc = ReadBytes(&MsgType, 4);
assert(rc == 4 && "Error reading message type.");
assert(MsgType == (uint32_t)ExpectedMsgType && "Error: received unexpected message type.");
uint32_t DataSize;
rc = ReadBytes(&DataSize, 4);
assert(rc == 4 && "Error reading data size.");
assert(DataSize == 0 && "Error: unexpected data size.");
}
void RemoteTargetExternal::Receive(LLIMessageType ExpectedMsgType, int &Data) {
uint64_t Temp;
Receive(ExpectedMsgType, Temp);
Data = (int)(int64_t)Temp;
}
void RemoteTargetExternal::Receive(LLIMessageType ExpectedMsgType, uint64_t &Data) {
int rc;
uint32_t MsgType;
rc = ReadBytes(&MsgType, 4);
assert(rc == 4 && "Error reading message type.");
assert(MsgType == (uint32_t)ExpectedMsgType && "Error: received unexpected message type.");
uint32_t DataSize;
rc = ReadBytes(&DataSize, 4);
assert(rc == 4 && "Error reading data size.");
assert(DataSize == 8 && "Error: unexpected data size.");
rc = ReadBytes(&Data, 8);
assert(DataSize == 8 && "Error: unexpected data.");
}
#ifdef LLVM_ON_UNIX
#include "Unix/RemoteTargetExternal.inc"
#endif
#ifdef LLVM_ON_WIN32
#include "Windows/RemoteTargetExternal.inc"
#endif