| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| ; RUN: %lli -jit-kind=orc-mcjit -extra-module=%p/Inputs/multi-module-b.ll -extra-module=%p/Inputs/multi-module-c.ll -disable-lazy-compilation=true -remote-mcjit -mcjit-remote-process=lli-child-target%exeext -relocation-model=pic -code-model=small %s > /dev/null | ||
| ; XFAIL: mips, i686, i386, arm | ||
|
|
||
| declare i32 @FB() | ||
|
|
||
| define i32 @main() { | ||
| %r = call i32 @FB( ) ; <i32> [#uses=1] | ||
| ret i32 %r | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| ; RUN: %lli -jit-kind=orc-mcjit %s > /dev/null | ||
|
|
||
| define i32 @main() { | ||
| ret i32 0 | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| ; RUN: %lli -jit-kind=orc-mcjit %s > /dev/null | ||
|
|
||
| define i32 @bar() { | ||
| ret i32 0 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| ; RUN: %lli -jit-kind=orc-mcjit -disable-lazy-compilation=false %s | ||
|
|
||
| define i32 @main() nounwind { | ||
| entry: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| ; RUN: %lli -jit-kind=orc-mcjit %s > /dev/null | ||
|
|
||
| define i32 @main() { | ||
| %A = add i8 0, 12 ; <i8> [#uses=1] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| ; RUN: %lli -jit-kind=orc-mcjit %s > /dev/null | ||
|
|
||
| ; test unconditional branch | ||
| define i32 @main() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| ; RUN: %lli -jit-kind=orc-mcjit %s > /dev/null | ||
|
|
||
| define i32 @_Z14func_exit_codev() nounwind uwtable { | ||
| entry: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| ; RUN: %lli -jit-kind=orc-mcjit %s > /dev/null | ||
|
|
||
| declare void @exit(i32) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| ; RUN: %lli -jit-kind=orc-mcjit %s > /dev/null | ||
|
|
||
| define i32 @foo() { | ||
| ret i32 0 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| ; RUN: %lli -jit-kind=orc-mcjit -O0 %s | ||
|
|
||
| ; Check that a variable is always aligned as specified. | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| ; RUN: %lli -jit-kind=orc-mcjit %s > /dev/null | ||
|
|
||
| @count = global i32 1, align 4 | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| ; RUN: %lli -jit-kind=orc-mcjit %s > /dev/null | ||
|
|
||
| @count = global i32 0, align 4 | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| ; RUN: %lli -jit-kind=orc-mcjit %s > /dev/null | ||
|
|
||
| define i32 @main() nounwind uwtable { | ||
| entry: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| ; RUN: %lli -jit-kind=orc-mcjit %s > /dev/null | ||
|
|
||
| define i32 @main() { | ||
| %A = and i8 4, 8 ; <i8> [#uses=2] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| ; RUN: %lli -jit-kind=orc-mcjit %s > /dev/null | ||
|
|
||
| define i32 @main() { | ||
| ; <label>:0 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| ; RUN: %lli -jit-kind=orc-mcjit %s > /dev/null | ||
|
|
||
| ; test phi node | ||
| @Y = global i32 6 ; <i32*> [#uses=1] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| ; RUN: %lli -jit-kind=orc-mcjit %s > /dev/null | ||
|
|
||
| ; test return instructions | ||
| define void @test1() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| ; RUN: %lli -jit-kind=orc-mcjit %s > /dev/null | ||
|
|
||
| define i32 @main() nounwind uwtable { | ||
| entry: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| ; RUN: %lli -jit-kind=orc-mcjit %s > /dev/null | ||
|
|
||
|
|
||
| define i32 @main() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| ; RUN: %lli -jit-kind=orc-mcjit %s > /dev/null | ||
|
|
||
| define i32 @main() { | ||
| %int1 = add i32 0, 0 ; <i32> [#uses=6] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| ; RUN: %lli -jit-kind=orc-mcjit %s > /dev/null | ||
|
|
||
| define i32 @main() { | ||
| %shamt = add i8 0, 1 ; <i8> [#uses=8] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| //===------ 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/ExecutionEngine/Orc/OrcTargetSupport.h" | ||
|
|
||
| using namespace llvm; | ||
|
|
||
| std::unique_ptr<OrcLazyJIT::CompileCallbackMgr> | ||
| OrcLazyJIT::createCallbackMgr(Triple T, LLVMContext &Context) { | ||
| switch (T.getArch()) { | ||
| default: | ||
| // Flag error. | ||
| Error = true; | ||
| return nullptr; | ||
|
|
||
| case Triple::x86_64: { | ||
| typedef orc::JITCompileCallbackManager<CompileLayerT, | ||
| orc::OrcX86_64> CCMgrT; | ||
| return make_unique<CCMgrT>(CompileLayer, Context, 0, 64); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| int llvm::runOrcLazyJIT(std::unique_ptr<Module> M, int ArgC, char* ArgV[]) { | ||
| OrcLazyJIT J(std::unique_ptr<TargetMachine>(EngineBuilder().selectTarget()), | ||
| getGlobalContext()); | ||
|
|
||
| if (!J.Ok()) { | ||
| errs() << "Could not construct JIT.\n"; | ||
| return 1; | ||
| } | ||
|
|
||
| auto MainHandle = J.addModule(std::move(M)); | ||
| auto MainSym = J.findSymbolIn(MainHandle, "main"); | ||
|
|
||
| if (!MainSym) { | ||
| errs() << "Could not find main function.\n"; | ||
| return 1; | ||
| } | ||
|
|
||
| typedef int (*MainFnPtr)(int, char*[]); | ||
| auto Main = reinterpret_cast<MainFnPtr>( | ||
| static_cast<uintptr_t>(MainSym.getAddress())); | ||
|
|
||
| return Main(ArgC, ArgV); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| //===--- 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/Triple.h" | ||
| #include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h" | ||
| #include "llvm/ExecutionEngine/Orc/CompileUtils.h" | ||
| #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h" | ||
| #include "llvm/ExecutionEngine/Orc/LazyEmittingLayer.h" | ||
| #include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h" | ||
| #include "llvm/IR/LLVMContext.h" | ||
|
|
||
| namespace llvm { | ||
|
|
||
| class OrcLazyJIT { | ||
| public: | ||
|
|
||
| typedef orc::JITCompileCallbackManagerBase CompileCallbackMgr; | ||
| typedef orc::ObjectLinkingLayer<> ObjLayerT; | ||
| typedef orc::IRCompileLayer<ObjLayerT> CompileLayerT; | ||
| typedef orc::LazyEmittingLayer<CompileLayerT> LazyEmitLayerT; | ||
| typedef orc::CompileOnDemandLayer<LazyEmitLayerT, | ||
| CompileCallbackMgr> CODLayerT; | ||
| typedef typename CODLayerT::ModuleSetHandleT ModuleHandleT; | ||
|
|
||
| OrcLazyJIT(std::unique_ptr<TargetMachine> TM, LLVMContext &Context) | ||
| : Error(false), TM(std::move(TM)), | ||
| Mang(this->TM->getDataLayout()), | ||
| ObjectLayer([](){ return llvm::make_unique<SectionMemoryManager>(); }), | ||
| CompileLayer(ObjectLayer, orc::SimpleCompiler(*this->TM)), | ||
| LazyEmitLayer(CompileLayer), | ||
| CCMgr(createCallbackMgr(Triple(this->TM->getTargetTriple()), Context)), | ||
| CODLayer(LazyEmitLayer, *CCMgr) { } | ||
|
|
||
| bool Ok() const { return !Error; } | ||
|
|
||
| ModuleHandleT addModule(std::unique_ptr<Module> M) { | ||
| // Attach a data-layout if one isn't already present. | ||
| if (M->getDataLayout().isDefault()) | ||
| M->setDataLayout(*TM->getDataLayout()); | ||
|
|
||
| std::vector<std::unique_ptr<Module>> S; | ||
| S.push_back(std::move(M)); | ||
| return CODLayer.addModuleSet(std::move(S)); | ||
| } | ||
|
|
||
| orc::JITSymbol findSymbol(const std::string &Name) { | ||
| return CODLayer.findSymbol(mangle(Name), true); | ||
| } | ||
|
|
||
| orc::JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name) { | ||
| return CODLayer.findSymbolIn(H, mangle(Name), true); | ||
| } | ||
|
|
||
| private: | ||
|
|
||
| std::unique_ptr<CompileCallbackMgr> | ||
| createCallbackMgr(Triple T, LLVMContext &Context); | ||
|
|
||
| std::string mangle(const std::string &Name) { | ||
| std::string MangledName; | ||
| { | ||
| raw_string_ostream MangledNameStream(MangledName); | ||
| Mang.getNameWithPrefix(MangledNameStream, Name); | ||
| } | ||
| return MangledName; | ||
| } | ||
|
|
||
| bool Error; | ||
| std::unique_ptr<TargetMachine> TM; | ||
| Mangler Mang; | ||
|
|
||
| ObjLayerT ObjectLayer; | ||
| CompileLayerT CompileLayer; | ||
| LazyEmitLayerT LazyEmitLayer; | ||
| std::unique_ptr<CompileCallbackMgr> CCMgr; | ||
| CODLayerT CODLayer; | ||
| }; | ||
|
|
||
| int runOrcLazyJIT(std::unique_ptr<Module> M, int ArgC, char* ArgV[]); | ||
|
|
||
| } // end namespace llvm | ||
|
|
||
| #endif |