Imported Upstream version 5.18.0.167

Former-commit-id: 289509151e0fee68a1b591a20c9f109c3c789d3a
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-10-20 08:25:10 +00:00
parent e19d552987
commit b084638f15
28489 changed files with 184 additions and 3866856 deletions

View File

@@ -1,46 +0,0 @@
if ( LLVM_INCLUDE_UTILS )
add_subdirectory(ChildTarget)
endif()
set(LLVM_LINK_COMPONENTS
CodeGen
Core
ExecutionEngine
IRReader
Interpreter
MC
MCJIT
Object
OrcJIT
RuntimeDyld
SelectionDAG
Support
Target
TransformUtils
native
)
if( LLVM_USE_OPROFILE )
set(LLVM_LINK_COMPONENTS
${LLVM_LINK_COMPONENTS}
OProfileJIT
)
endif( LLVM_USE_OPROFILE )
if( LLVM_USE_INTEL_JITEVENTS )
set(LLVM_LINK_COMPONENTS
${LLVM_LINK_COMPONENTS}
DebugInfoDWARF
IntelJITEvents
Object
)
endif( LLVM_USE_INTEL_JITEVENTS )
add_llvm_tool(lli
lli.cpp
OrcLazyJIT.cpp
DEPENDS
intrinsics_gen
)
export_executable_symbols(lli)

View File

@@ -1,13 +0,0 @@
set(LLVM_LINK_COMPONENTS
OrcJIT
RuntimeDyld
Support
)
add_llvm_utility(lli-child-target
ChildTarget.cpp
DEPENDS
intrinsics_gen
)

View File

@@ -1,67 +0,0 @@
#include "llvm/ExecutionEngine/Orc/OrcABISupport.h"
#include "llvm/ExecutionEngine/Orc/OrcRemoteTargetServer.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/Process.h"
#include <sstream>
#include "../RemoteJITUtils.h"
using namespace llvm;
using namespace llvm::orc;
using namespace llvm::sys;
#ifdef __x86_64__
typedef OrcX86_64_SysV HostOrcArch;
#else
typedef OrcGenericABI HostOrcArch;
#endif
ExitOnError ExitOnErr;
int main(int argc, char *argv[]) {
if (argc != 3) {
errs() << "Usage: " << argv[0] << " <input fd> <output fd>\n";
return 1;
}
ExitOnErr.setBanner(std::string(argv[0]) + ":");
int InFD;
int OutFD;
{
std::istringstream InFDStream(argv[1]), OutFDStream(argv[2]);
InFDStream >> InFD;
OutFDStream >> OutFD;
}
if (sys::DynamicLibrary::LoadLibraryPermanently(nullptr)) {
errs() << "Error loading program symbols.\n";
return 1;
}
auto SymbolLookup = [](const std::string &Name) {
return RTDyldMemoryManager::getSymbolAddressInProcess(Name);
};
auto RegisterEHFrames = [](uint8_t *Addr, uint32_t Size) {
RTDyldMemoryManager::registerEHFramesInProcess(Addr, Size);
};
auto DeregisterEHFrames = [](uint8_t *Addr, uint32_t Size) {
RTDyldMemoryManager::deregisterEHFramesInProcess(Addr, Size);
};
FDRawChannel Channel(InFD, OutFD);
typedef remote::OrcRemoteTargetServer<FDRawChannel, HostOrcArch> JITServer;
JITServer Server(Channel, SymbolLookup, RegisterEHFrames, DeregisterEHFrames);
while (!Server.receivedTerminate())
ExitOnErr(Server.handleOne());
close(InFD);
close(OutFD);
return 0;
}

View File

@@ -1,21 +0,0 @@
;===- ./tools/lli/ChildTarget/LLVMBuild.txt --------------------*- Conf -*--===;
;
; The LLVM Compiler Infrastructure
;
; This file is distributed under the University of Illinois Open Source
; License. See LICENSE.TXT for details.
;
;===------------------------------------------------------------------------===;
;
; This is an LLVMBuild description file for the components in this subdirectory.
;
; For more information on the LLVMBuild system, please see:
;
; http://llvm.org/docs/LLVMBuild.html
;
;===------------------------------------------------------------------------===;
[component_0]
type = Tool
name = lli-child-target
parent = lli

View File

@@ -1,35 +0,0 @@
;===- ./tools/lli/LLVMBuild.txt --------------------------------*- Conf -*--===;
;
; The LLVM Compiler Infrastructure
;
; This file is distributed under the University of Illinois Open Source
; License. See LICENSE.TXT for details.
;
;===------------------------------------------------------------------------===;
;
; This is an LLVMBuild description file for the components in this subdirectory.
;
; For more information on the LLVMBuild system, please see:
;
; http://llvm.org/docs/LLVMBuild.html
;
;===------------------------------------------------------------------------===;
[common]
subdirectories = ChildTarget
[component_0]
type = Tool
name = lli
parent = Tools
required_libraries =
AsmParser
BitReader
IRReader
Instrumentation
Interpreter
MCJIT
Native
NativeCodeGen
SelectionDAG
TransformUtils

View File

@@ -1,166 +0,0 @@
//===- OrcLazyJIT.cpp - Basic Orc-based JIT for lazy execution ------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "OrcLazyJIT.h"
#include "llvm/ADT/Triple.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <system_error>
using namespace llvm;
namespace {
enum class DumpKind {
NoDump,
DumpFuncsToStdOut,
DumpModsToStdOut,
DumpModsToDisk
};
} // end anonymous namespace
static cl::opt<DumpKind> OrcDumpKind(
"orc-lazy-debug", cl::desc("Debug dumping for the orc-lazy JIT."),
cl::init(DumpKind::NoDump),
cl::values(clEnumValN(DumpKind::NoDump, "no-dump", "Don't dump anything."),
clEnumValN(DumpKind::DumpFuncsToStdOut, "funcs-to-stdout",
"Dump function names to stdout."),
clEnumValN(DumpKind::DumpModsToStdOut, "mods-to-stdout",
"Dump modules to stdout."),
clEnumValN(DumpKind::DumpModsToDisk, "mods-to-disk",
"Dump modules to the current "
"working directory. (WARNING: "
"will overwrite existing files).")),
cl::Hidden);
static cl::opt<bool> OrcInlineStubs("orc-lazy-inline-stubs",
cl::desc("Try to inline stubs"),
cl::init(true), cl::Hidden);
OrcLazyJIT::TransformFtor OrcLazyJIT::createDebugDumper() {
switch (OrcDumpKind) {
case DumpKind::NoDump:
return [](std::shared_ptr<Module> M) { return M; };
case DumpKind::DumpFuncsToStdOut:
return [](std::shared_ptr<Module> M) {
printf("[ ");
for (const auto &F : *M) {
if (F.isDeclaration())
continue;
if (F.hasName()) {
std::string Name(F.getName());
printf("%s ", Name.c_str());
} else
printf("<anon> ");
}
printf("]\n");
return M;
};
case DumpKind::DumpModsToStdOut:
return [](std::shared_ptr<Module> M) {
outs() << "----- Module Start -----\n" << *M
<< "----- Module End -----\n";
return M;
};
case DumpKind::DumpModsToDisk:
return [](std::shared_ptr<Module> M) {
std::error_code EC;
raw_fd_ostream Out(M->getModuleIdentifier() + ".ll", EC,
sys::fs::F_Text);
if (EC) {
errs() << "Couldn't open " << M->getModuleIdentifier()
<< " for dumping.\nError:" << EC.message() << "\n";
exit(1);
}
Out << *M;
return M;
};
}
llvm_unreachable("Unknown DumpKind");
}
// Defined in lli.cpp.
CodeGenOpt::Level getOptLevel();
template <typename PtrTy>
static PtrTy fromTargetAddress(JITTargetAddress Addr) {
return reinterpret_cast<PtrTy>(static_cast<uintptr_t>(Addr));
}
int llvm::runOrcLazyJIT(std::vector<std::unique_ptr<Module>> Ms,
const std::vector<std::string> &Args) {
// Add the program's symbols into the JIT's search space.
if (sys::DynamicLibrary::LoadLibraryPermanently(nullptr)) {
errs() << "Error loading program symbols.\n";
return 1;
}
// Grab a target machine and try to build a factory function for the
// target-specific Orc callback manager.
EngineBuilder EB;
EB.setOptLevel(getOptLevel());
auto TM = std::unique_ptr<TargetMachine>(EB.selectTarget());
Triple T(TM->getTargetTriple());
auto CompileCallbackMgr = orc::createLocalCompileCallbackManager(T, 0);
// If we couldn't build the factory function then there must not be a callback
// manager for this target. Bail out.
if (!CompileCallbackMgr) {
errs() << "No callback manager available for target '"
<< TM->getTargetTriple().str() << "'.\n";
return 1;
}
auto IndirectStubsMgrBuilder = orc::createLocalIndirectStubsManagerBuilder(T);
// If we couldn't build a stubs-manager-builder for this target then bail out.
if (!IndirectStubsMgrBuilder) {
errs() << "No indirect stubs manager available for target '"
<< TM->getTargetTriple().str() << "'.\n";
return 1;
}
// Everything looks good. Build the JIT.
OrcLazyJIT J(std::move(TM), std::move(CompileCallbackMgr),
std::move(IndirectStubsMgrBuilder),
OrcInlineStubs);
// Add the module, look up main and run it.
for (auto &M : Ms)
cantFail(J.addModule(std::shared_ptr<Module>(std::move(M))));
if (auto MainSym = J.findSymbol("main")) {
typedef int (*MainFnPtr)(int, const char*[]);
std::vector<const char *> ArgV;
for (auto &Arg : Args)
ArgV.push_back(Arg.c_str());
auto Main = fromTargetAddress<MainFnPtr>(cantFail(MainSym.getAddress()));
return Main(ArgV.size(), (const char**)ArgV.data());
} else if (auto Err = MainSym.takeError())
logAllUnhandledErrors(std::move(Err), llvm::errs(), "");
else
errs() << "Could not find main function.\n";
return 1;
}

View File

@@ -1,201 +0,0 @@
//===- OrcLazyJIT.h - Basic Orc-based JIT for lazy execution ----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Simple Orc-based JIT. Uses the compile-on-demand layer to break up and
// lazily compile modules.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TOOLS_LLI_ORCLAZYJIT_H
#define LLVM_TOOLS_LLI_ORCLAZYJIT_H
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/Twine.h"
#include "llvm/ExecutionEngine/JITSymbol.h"
#include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h"
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
#include "llvm/ExecutionEngine/Orc/IRTransformLayer.h"
#include "llvm/ExecutionEngine/Orc/IndirectionUtils.h"
#include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/Mangler.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
#include <algorithm>
#include <functional>
#include <memory>
#include <set>
#include <string>
#include <vector>
namespace llvm {
class OrcLazyJIT {
public:
using CompileCallbackMgr = orc::JITCompileCallbackManager;
using ObjLayerT = orc::RTDyldObjectLinkingLayer;
using CompileLayerT = orc::IRCompileLayer<ObjLayerT, orc::SimpleCompiler>;
using TransformFtor =
std::function<std::shared_ptr<Module>(std::shared_ptr<Module>)>;
using IRDumpLayerT = orc::IRTransformLayer<CompileLayerT, TransformFtor>;
using CODLayerT = orc::CompileOnDemandLayer<IRDumpLayerT, CompileCallbackMgr>;
using IndirectStubsManagerBuilder = CODLayerT::IndirectStubsManagerBuilderT;
using ModuleHandleT = CODLayerT::ModuleHandleT;
OrcLazyJIT(std::unique_ptr<TargetMachine> TM,
std::unique_ptr<CompileCallbackMgr> CCMgr,
IndirectStubsManagerBuilder IndirectStubsMgrBuilder,
bool InlineStubs)
: TM(std::move(TM)), DL(this->TM->createDataLayout()),
CCMgr(std::move(CCMgr)),
ObjectLayer([]() { return std::make_shared<SectionMemoryManager>(); }),
CompileLayer(ObjectLayer, orc::SimpleCompiler(*this->TM)),
IRDumpLayer(CompileLayer, createDebugDumper()),
CODLayer(IRDumpLayer, extractSingleFunction, *this->CCMgr,
std::move(IndirectStubsMgrBuilder), InlineStubs),
CXXRuntimeOverrides(
[this](const std::string &S) { return mangle(S); }) {}
~OrcLazyJIT() {
// Run any destructors registered with __cxa_atexit.
CXXRuntimeOverrides.runDestructors();
// Run any IR destructors.
for (auto &DtorRunner : IRStaticDestructorRunners)
if (auto Err = DtorRunner.runViaLayer(CODLayer)) {
// FIXME: OrcLazyJIT should probably take a "shutdownError" callback to
// report these errors on.
report_fatal_error(std::move(Err));
}
}
Error addModule(std::shared_ptr<Module> M) {
if (M->getDataLayout().isDefault())
M->setDataLayout(DL);
// Rename, bump linkage and record static constructors and destructors.
// We have to do this before we hand over ownership of the module to the
// JIT.
std::vector<std::string> CtorNames, DtorNames;
{
unsigned CtorId = 0, DtorId = 0;
for (auto Ctor : orc::getConstructors(*M)) {
std::string NewCtorName = ("$static_ctor." + Twine(CtorId++)).str();
Ctor.Func->setName(NewCtorName);
Ctor.Func->setLinkage(GlobalValue::ExternalLinkage);
Ctor.Func->setVisibility(GlobalValue::HiddenVisibility);
CtorNames.push_back(mangle(NewCtorName));
}
for (auto Dtor : orc::getDestructors(*M)) {
std::string NewDtorName = ("$static_dtor." + Twine(DtorId++)).str();
Dtor.Func->setLinkage(GlobalValue::ExternalLinkage);
Dtor.Func->setVisibility(GlobalValue::HiddenVisibility);
DtorNames.push_back(mangle(Dtor.Func->getName()));
Dtor.Func->setName(NewDtorName);
}
}
// Symbol resolution order:
// 1) Search the JIT symbols.
// 2) Check for C++ runtime overrides.
// 3) Search the host process (LLI)'s symbol table.
if (!ModulesHandle) {
auto Resolver =
orc::createLambdaResolver(
[this](const std::string &Name) -> JITSymbol {
if (auto Sym = CODLayer.findSymbol(Name, true))
return Sym;
return CXXRuntimeOverrides.searchOverrides(Name);
},
[](const std::string &Name) {
if (auto Addr =
RTDyldMemoryManager::getSymbolAddressInProcess(Name))
return JITSymbol(Addr, JITSymbolFlags::Exported);
return JITSymbol(nullptr);
}
);
// Add the module to the JIT.
if (auto ModulesHandleOrErr =
CODLayer.addModule(std::move(M), std::move(Resolver)))
ModulesHandle = std::move(*ModulesHandleOrErr);
else
return ModulesHandleOrErr.takeError();
} else if (auto Err = CODLayer.addExtraModule(*ModulesHandle, std::move(M)))
return Err;
// Run the static constructors, and save the static destructor runner for
// execution when the JIT is torn down.
orc::CtorDtorRunner<CODLayerT> CtorRunner(std::move(CtorNames),
*ModulesHandle);
if (auto Err = CtorRunner.runViaLayer(CODLayer))
return Err;
IRStaticDestructorRunners.emplace_back(std::move(DtorNames),
*ModulesHandle);
return Error::success();
}
JITSymbol findSymbol(const std::string &Name) {
return CODLayer.findSymbol(mangle(Name), true);
}
JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name) {
return CODLayer.findSymbolIn(H, mangle(Name), true);
}
private:
std::string mangle(const std::string &Name) {
std::string MangledName;
{
raw_string_ostream MangledNameStream(MangledName);
Mangler::getNameWithPrefix(MangledNameStream, Name, DL);
}
return MangledName;
}
static std::set<Function*> extractSingleFunction(Function &F) {
std::set<Function*> Partition;
Partition.insert(&F);
return Partition;
}
static TransformFtor createDebugDumper();
std::unique_ptr<TargetMachine> TM;
DataLayout DL;
SectionMemoryManager CCMgrMemMgr;
std::unique_ptr<CompileCallbackMgr> CCMgr;
ObjLayerT ObjectLayer;
CompileLayerT CompileLayer;
IRDumpLayerT IRDumpLayer;
CODLayerT CODLayer;
orc::LocalCXXRuntimeOverrides CXXRuntimeOverrides;
std::vector<orc::CtorDtorRunner<CODLayerT>> IRStaticDestructorRunners;
llvm::Optional<CODLayerT::ModuleHandleT> ModulesHandle;
};
int runOrcLazyJIT(std::vector<std::unique_ptr<Module>> Ms,
const std::vector<std::string> &Args);
} // end namespace llvm
#endif // LLVM_TOOLS_LLI_ORCLAZYJIT_H

View File

@@ -1,152 +0,0 @@
//===-- 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/RawByteChannel.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 FDRawChannel final : public llvm::orc::rpc::RawByteChannel {
public:
FDRawChannel(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;
};
// launch the remote process (see lli.cpp) and return a channel to it.
std::unique_ptr<FDRawChannel> launchRemote();
namespace llvm {
// ForwardingMM - Adapter to connect MCJIT to Orc's Remote8
// memory manager.
class ForwardingMemoryManager : public llvm::RTDyldMemoryManager {
public:
void setMemMgr(std::unique_ptr<RuntimeDyld::MemoryManager> MemMgr) {
this->MemMgr = std::move(MemMgr);
}
void setResolver(std::shared_ptr<JITSymbolResolver> Resolver) {
this->Resolver = std::move(Resolver);
}
uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
unsigned SectionID,
StringRef SectionName) override {
return MemMgr->allocateCodeSection(Size, Alignment, SectionID, SectionName);
}
uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
unsigned SectionID, StringRef SectionName,
bool IsReadOnly) override {
return MemMgr->allocateDataSection(Size, Alignment, SectionID, SectionName,
IsReadOnly);
}
void reserveAllocationSpace(uintptr_t CodeSize, uint32_t CodeAlign,
uintptr_t RODataSize, uint32_t RODataAlign,
uintptr_t RWDataSize,
uint32_t RWDataAlign) override {
MemMgr->reserveAllocationSpace(CodeSize, CodeAlign, RODataSize, RODataAlign,
RWDataSize, RWDataAlign);
}
bool needsToReserveAllocationSpace() override {
return MemMgr->needsToReserveAllocationSpace();
}
void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr,
size_t Size) override {
MemMgr->registerEHFrames(Addr, LoadAddr, Size);
}
void deregisterEHFrames() override {
MemMgr->deregisterEHFrames();
}
bool finalizeMemory(std::string *ErrMsg = nullptr) override {
return MemMgr->finalizeMemory(ErrMsg);
}
void notifyObjectLoaded(RuntimeDyld &RTDyld,
const object::ObjectFile &Obj) override {
MemMgr->notifyObjectLoaded(RTDyld, Obj);
}
// Don't hide the sibling notifyObjectLoaded from RTDyldMemoryManager.
using RTDyldMemoryManager::notifyObjectLoaded;
JITSymbol findSymbol(const std::string &Name) override {
return Resolver->findSymbol(Name);
}
JITSymbol
findSymbolInLogicalDylib(const std::string &Name) override {
return Resolver->findSymbolInLogicalDylib(Name);
}
private:
std::unique_ptr<RuntimeDyld::MemoryManager> MemMgr;
std::shared_ptr<JITSymbolResolver> Resolver;
};
}
#endif

File diff suppressed because it is too large Load Diff