20 TMOwningSimpleCompiler(std::unique_ptr<llvm::TargetMachine>
TM)
21 :
llvm::orc::SimpleCompiler(*TM), TM(
std::move(TM)) {}
25 std::shared_ptr<llvm::TargetMachine>
TM;
35 CompileThreads->wait();
40 unsigned NumCompileThreads) {
42 if (NumCompileThreads == 0) {
46 return TM.takeError();
47 return std::unique_ptr<LLJIT>(
new LLJIT(llvm::make_unique<ExecutionSession>(),
48 std::move(*
TM), std::move(DL)));
51 return std::unique_ptr<LLJIT>(
new LLJIT(llvm::make_unique<ExecutionSession>(),
52 std::move(JTMB), std::move(DL),
57 auto InternedName = ES->intern(Name);
63 assert(TSM &&
"Can not add null module");
65 if (
auto Err = applyDataLayout(*TSM.
getModule()))
68 return CompileLayer.add(JD, std::move(TSM), ES->allocateVModule());
71 Error LLJIT::addObjectFile(
JITDylib &JD, std::unique_ptr<MemoryBuffer> Obj) {
72 assert(Obj &&
"Can not add null object");
74 return ObjLinkingLayer.add(JD, std::move(Obj), ES->allocateVModule());
82 LLJIT::LLJIT(std::unique_ptr<ExecutionSession> ES,
84 : ES(
std::move(ES)), Main(this->ES->getMainJITDylib()), DL(
std::move(DL)),
87 []() {
return llvm::make_unique<SectionMemoryManager>(); }),
89 TMOwningSimpleCompiler(std::move(
TM))),
97 []() {
return llvm::make_unique<SectionMemoryManager>(); }),
101 assert(NumCompileThreads != 0 &&
102 "Multithreaded LLJIT instance can not be created with 0 threads");
110 CompileThreads = llvm::make_unique<ThreadPool>(NumCompileThreads);
111 this->
ES->setDispatchMaterialization(
112 [
this](
JITDylib &JD, std::unique_ptr<MaterializationUnit> MU) {
114 auto SharedMU = std::shared_ptr<MaterializationUnit>(std::move(MU));
115 auto Work = [SharedMU, &JD]() { SharedMU->doMaterialize(JD); };
121 std::string MangledName;
134 return make_error<StringError>(
135 "Added modules have incompatible data layouts",
149 auto ES = llvm::make_unique<ExecutionSession>();
155 return LCTMgr.takeError();
159 return make_error<StringError>(
160 std::string(
"No indirect stubs manager builder for ") + TT.str(),
163 if (NumCompileThreads == 0) {
166 return TM.takeError();
167 return std::unique_ptr<LLLazyJIT>(
169 std::move(*LCTMgr), std::move(ISMBuilder)));
172 return std::unique_ptr<LLLazyJIT>(
new LLLazyJIT(
173 std::move(
ES), std::move(JTMB), std::move(DL), NumCompileThreads,
174 std::move(*LCTMgr), std::move(ISMBuilder)));
178 assert(TSM &&
"Can not add null module");
185 return CODLayer.add(JD, std::move(TSM),
ES->allocateVModule());
188 LLLazyJIT::LLLazyJIT(
189 std::unique_ptr<ExecutionSession>
ES, std::unique_ptr<TargetMachine>
TM,
190 DataLayout DL, std::unique_ptr<LazyCallThroughManager> LCTMgr,
191 std::function<std::unique_ptr<IndirectStubsManager>()> ISMBuilder)
192 :
LLJIT(std::move(ES), std::move(TM), std::move(DL)),
193 LCTMgr(std::move(LCTMgr)), TransformLayer(*this->ES,
CompileLayer),
194 CODLayer(*this->ES, TransformLayer, *this->LCTMgr,
195 std::move(ISMBuilder)) {}
197 LLLazyJIT::LLLazyJIT(
200 std::unique_ptr<LazyCallThroughManager> LCTMgr,
201 std::function<std::unique_ptr<IndirectStubsManager>()> ISMBuilder)
202 :
LLJIT(std::move(ES), std::move(JTMB), std::move(DL), NumCompileThreads),
203 LCTMgr(std::move(LCTMgr)), TransformLayer(*this->ES,
CompileLayer),
204 CODLayer(*this->ES, TransformLayer, *this->LCTMgr,
205 std::move(ISMBuilder)) {
206 CODLayer.setCloneToNewContextOnEmit(
true);
A parsed version of the target data layout string in and methods for querying it. ...
IRCompileLayer CompileLayer
This class represents lattice values for constants.
std::function< std::unique_ptr< IndirectStubsManager >)> createLocalIndirectStubsManagerBuilder(const Triple &T)
Create a local indriect stubs manager builder.
A Module instance is used to store all the information related to an LLVM module. ...
void setDataLayout(StringRef Desc)
Set the data layout.
Error addLazyIRModule(JITDylib &JD, ThreadSafeModule M)
Add a module to be lazily compiled to JITDylib JD.
RTDyldObjectLinkingLayer ObjLinkingLayer
std::unique_ptr< AbsoluteSymbolsMaterializationUnit > absoluteSymbols(SymbolMap Symbols, VModuleKey K=VModuleKey())
Create an AbsoluteSymbolsMaterializationUnit with the given symbols.
amdgpu Simplify well known AMD library false Value Value const Twine & Name
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
A thread-safe version of SimpleCompiler.
std::vector< std::pair< JITDylib *, bool > > JITDylibSearchList
A list of (JITDylib*, bool) pairs.
Tagged union holding either a T or a Error.
Simple compile functor: Takes a single IR module and returns an ObjectFile.
void add(iterator_range< CtorDtorIterator > CtorDtors)
CtorDtorRunner DtorRunner
iterator_range< CtorDtorIterator > getDestructors(const Module &M)
Create an iterator range over the entries of the llvm.global_ctors array.
uint64_t JITTargetAddress
Represents an address in the target process's address space.
Module * getModule()
Get the module wrapped by this ThreadSafeModule.
void setCloneToNewContextOnEmit(bool CloneToNewContextOnEmit)
Sets the CloneToNewContextOnEmit flag (false by default).
std::string mangle(StringRef UnmangledName)
LLJIT(std::unique_ptr< ExecutionSession > ES, std::unique_ptr< TargetMachine > TM, DataLayout DL)
Create an LLJIT instance with a single compile thread.
An LLVM Module together with a shared ThreadSafeContext.
CtorDtorRunner CtorRunner
Triple - Helper class for working with autoconf configuration names.
std::unique_ptr< ThreadPool > CompileThreads
std::unique_ptr< ExecutionSession > ES
static ErrorSuccess success()
Create a success value.
void recordCtorDtors(Module &M)
Expected< std::unique_ptr< LazyCallThroughManager > > createLocalLazyCallThroughManager(const Triple &T, ExecutionSession &ES, JITTargetAddress ErrorHandlerAddr)
Create a LocalLazyCallThroughManager from the given triple and execution session. ...
Triple & getTargetTriple()
Access Triple.
bool isDefault() const
Test if the DataLayout was constructed from an empty string.
A pre-fabricated ORC JIT stack that can serve as an alternative to MCJIT.
An extended version of LLJIT that supports lazy function-at-a-time compilation of LLVM IR...
Represents a symbol that has been evaluated to an address already.
Expected< std::unique_ptr< TargetMachine > > createTargetMachine()
Create a TargetMachine.
iterator_range< CtorDtorIterator > getConstructors(const Module &M)
Create an iterator range over the entries of the llvm.global_ctors array.
Error applyDataLayout(Module &M)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A raw_ostream that writes to an std::string.
Lightweight error class with error context and mandatory checking.
void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV, bool CannotUsePrivateLabel) const
Print the appropriate prefix and the specified global variable's name.
print Print MemDeps of function
StringRef - Represent a constant reference to a string, i.e.
JITDylib & getMainJITDylib()
Returns a reference to the JITDylib representing the JIT'd main program.
static Expected< std::unique_ptr< LLLazyJIT > > Create(JITTargetMachineBuilder JTMB, DataLayout DL, JITTargetAddress ErrorAddr, unsigned NumCompileThreads=0)
Create an LLLazyJIT instance.
A symbol table that supports asynchoronous symbol queries.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
A utility class for building TargetMachines for JITs.