24 JTMB = std::move(*JTMBOrErr);
26 return JTMBOrErr.takeError();
32 JTMB->getRelocationModel() ==
None) {
34 auto &
TT =
JTMB->getTargetTriple();
35 if (
TT.isOSBinFormatMachO() &&
42 const Triple &) -> std::unique_ptr<ObjectLayer> {
43 return std::make_unique<ObjectLinkingLayer>(
44 ES, std::make_unique<jitlink::InProcessMemoryManager>());
54 CompileThreads->wait();
58 auto InternedName =
ES->intern(Name);
64 assert(TSM &&
"Can not add null module");
70 return CompileLayer->add(JD, std::move(TSM),
ES->allocateVModule());
74 assert(Obj &&
"Can not add null object");
76 return ObjTransformLayer.add(JD, std::move(Obj),
ES->allocateVModule());
86 std::unique_ptr<ObjectLayer>
95 auto GetMemMgr = []() {
return std::make_unique<SectionMemoryManager>(); };
96 auto ObjLinkingLayer =
97 std::make_unique<RTDyldObjectLinkingLayer>(
ES, std::move(GetMemMgr));
99 if (S.
JTMB->getTargetTriple().isOSBinFormatCOFF()) {
100 ObjLinkingLayer->setOverrideObjectFlagsWithResponsibilityFlags(
true);
101 ObjLinkingLayer->setAutoClaimResponsibilityForObjectSymbols(
true);
107 return std::unique_ptr<ObjectLayer>(std::move(ObjLinkingLayer));
121 return std::make_unique<ConcurrentIRCompiler>(std::move(JTMB));
125 return TM.takeError();
127 return std::make_unique<TMOwningSimpleCompiler>(std::move(*TM));
132 Main(this->
ES->createJITDylib(
"<main>")), DL(
""),
133 ObjLinkingLayer(createObjectLinkingLayer(S, *
ES)),
134 ObjTransformLayer(*this->
ES, *ObjLinkingLayer), CtorRunner(Main),
139 if (
auto DLOrErr = S.
JTMB->getDefaultDataLayoutForTarget())
140 DL = std::move(*DLOrErr);
142 Err = DLOrErr.takeError();
148 if (!CompileFunction) {
149 Err = CompileFunction.takeError();
159 ES->setDispatchMaterialization(
160 [
this](
JITDylib &JD, std::unique_ptr<MaterializationUnit> MU) {
162 auto SharedMU = std::shared_ptr<MaterializationUnit>(std::move(MU));
163 auto Work = [SharedMU, &JD]() { SharedMU->doMaterialize(JD); };
170 std::string MangledName;
183 return make_error<StringError>(
184 "Added modules have incompatible data layouts",
198 TT = JTMB->getTargetTriple();
203 assert(TSM &&
"Can not add null module");
206 if (auto Err = applyDataLayout(M))
210 return Error::success();
214 return CODLayer->add(JD, std::move(TSM),
ES->allocateVModule());
227 LCTMgr = std::move(S.
LCTMgr);
231 LCTMgr = std::move(*LCTMgrOrErr);
233 Err = LCTMgrOrErr.takeError();
247 Err = make_error<StringError>(
"Could not construct " 248 "IndirectStubsManagerBuilder for target " +
255 TransformLayer = std::make_unique<IRTransformLayer>(*
ES, *
CompileLayer);
258 CODLayer = std::make_unique<CompileOnDemandLayer>(
259 *
ES, *TransformLayer, *LCTMgr, std::move(ISMBuilder));
262 CODLayer->setCloneToNewContextOnEmit(
true);
This class represents lattice values for constants.
std::function< std::unique_ptr< IndirectStubsManager >)> createLocalIndirectStubsManagerBuilder(const Triple &T)
Create a local indriect stubs manager builder.
Error defineAbsolute(StringRef Name, JITEvaluatedSymbol Address)
Convenience method for defining an absolute symbol.
A Module instance is used to store all the information related to an LLVM module. ...
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
LLJIT(LLJITBuilderState &S, Error &Err)
Create an LLJIT instance with a single compile thread.
auto withModuleDo(Func &&F) -> decltype(F(std::declval< Module &>()))
Locks the associated ThreadSafeContext and calls the given function on the contained Module...
std::unique_ptr< ExecutionSession > ES
Error addIRModule(JITDylib &JD, ThreadSafeModule TSM)
Adds an IR module to the given JITDylib.
void setDataLayout(StringRef Desc)
Set the data layout.
Error addLazyIRModule(JITDylib &JD, ThreadSafeModule M)
Add a module to be lazily compiled to JITDylib JD.
std::unique_ptr< AbsoluteSymbolsMaterializationUnit > absoluteSymbols(SymbolMap Symbols, VModuleKey K=VModuleKey())
Create an AbsoluteSymbolsMaterializationUnit with the given symbols.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Tagged union holding either a T or a Error.
void add(iterator_range< CtorDtorIterator > CtorDtors)
unsigned NumCompileThreads
CtorDtorRunner DtorRunner
iterator_range< CtorDtorIterator > getDestructors(const Module &M)
Create an iterator range over the entries of the llvm.global_ctors array.
const std::string & str() const
static Expected< JITTargetMachineBuilder > detectHost()
Create a JITTargetMachineBuilder for the host system.
static Expected< std::unique_ptr< IRCompileLayer::IRCompiler > > createCompileFunction(LLJITBuilderState &S, JITTargetMachineBuilder JTMB)
std::string mangle(StringRef UnmangledName)
std::unique_ptr< IRCompileLayer > CompileLayer
CompileFunctionCreator CreateCompileFunction
An LLVM Module together with a shared ThreadSafeContext.
CtorDtorRunner CtorRunner
JITDylibSearchOrder makeJITDylibSearchOrder(ArrayRef< JITDylib *> JDs, JITDylibLookupFlags Flags=JITDylibLookupFlags::MatchExportedSymbolsOnly)
Convenience function for creating a search order from an ArrayRef of JITDylib*, all with the same fla...
Triple - Helper class for working with autoconf configuration names.
ObjectLinkingLayerCreator CreateObjectLinkingLayer
std::unique_ptr< ThreadPool > CompileThreads
Error prepareForConstruction()
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. ...
bool isDefault() const
Test if the DataLayout was constructed from an empty string.
An ExecutionSession represents a running JIT program.
Represents a symbol that has been evaluated to an address already.
Helper for Errors used as out-parameters.
Expected< std::unique_ptr< TargetMachine > > createTargetMachine()
Create a TargetMachine.
Expected< JITEvaluatedSymbol > lookupLinkerMangled(JITDylib &JD, StringRef Name)
Look up a symbol in JITDylib JD by the symbol's linker-mangled name (to look up symbols based on thei...
Error addObjectFile(JITDylib &JD, std::unique_ptr< MemoryBuffer > Obj)
Adds an object file to the given JITDylib.
iterator_range< CtorDtorIterator > getConstructors(const Module &M)
Create an iterator range over the entries of the llvm.global_ctors array.
Error applyDataLayout(Module &M)
~LLJIT()
Destruct this instance.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::unique_ptr< LazyCallThroughManager > LCTMgr
A raw_ostream that writes to an std::string.
Error prepareForConstruction()
Called prior to JIT class construcion to fix up defaults.
Lightweight error class with error context and mandatory checking.
JITTargetAddress LazyCompileFailureAddr
void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV, bool CannotUsePrivateLabel) const
Print the appropriate prefix and the specified global variable's name.
StringRef - Represent a constant reference to a string, i.e.
static std::unique_ptr< ObjectLayer > createObjectLinkingLayer(LLJITBuilderState &S, ExecutionSession &ES)
Optional< JITTargetMachineBuilder > JTMB
IndirectStubsManagerBuilderFunction ISMBuilder
ObjectTransformLayer ObjTransformLayer
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.