17#define DEBUG_TYPE "orc"
25 assert(RT &&
"RT can not be null");
26 auto &JD = RT->getJITDylib();
27 return JD.define(std::make_unique<BasicIRLayerMaterializationUnit>(
37 assert(this->TSM &&
"Module must not be null");
41 for (
auto &
G : M.global_values()) {
44 if (!
G.hasName() ||
G.isDeclaration() ||
G.hasLocalLinkage() ||
45 G.hasAvailableExternallyLinkage() ||
G.hasAppendingLinkage())
55 auto EmuTLSV = Mangle((
"__emutls_v." + GV.getName()).str());
61 if (GV.hasInitializer()) {
62 const auto *InitVal = GV.getInitializer();
68 if (InitIntValue && InitIntValue->isZero())
71 auto EmuTLST = Mangle((
"__emutls_t." + GV.getName()).str());
78 auto MangledName = Mangle(
G.getName());
92 std::string InitSymbolName;
94 <<
"$." << M.getModuleIdentifier() <<
".__inits." << Counter++;
111 return TSM.withModuleDo(
113 return "<null module>";
116void IRMaterializationUnit::discard(
const JITDylib &JD,
119 dbgs() <<
"In " << JD.getName() <<
" discarding " << *Name <<
" from MU@"
120 << this <<
" (" << getName() <<
")\n";
125 "Symbol not provided by this MU, or previously discarded");
126 assert(!
I->second->isDeclaration() &&
127 "Discard should only apply to definitions");
132 GO->setComdat(
nullptr);
141void BasicIRLayerMaterializationUnit::materialize(
142 std::unique_ptr<MaterializationResponsibility> R) {
153 auto &ES = R->getTargetJITDylib().getExecutionSession();
154 auto &
N = R->getTargetJITDylib().getName();
158 [&]() { dbgs() <<
"Emitting, for " << N <<
", " << *this <<
"\n"; }););
159 L.
emit(std::move(R), std::move(
TSM));
161 dbgs() <<
"Finished emitting, for " << N <<
", " << *this <<
"\n";
173 assert(RT &&
"RT can not be null");
174 auto &JD = RT->getJITDylib();
175 return JD.
define(std::make_unique<BasicObjectLayerMaterializationUnit>(
176 *
this, std::move(O), std::move(
I)),
183 return I.takeError();
184 return add(std::move(RT), std::move(O), std::move(*
I));
190 return I.takeError();
191 return add(JD, std::move(O), std::move(*
I));
196 std::unique_ptr<MemoryBuffer> O) {
202 return ObjInterface.takeError();
204 return std::make_unique<BasicObjectLayerMaterializationUnit>(
205 L, std::move(O), std::move(*ObjInterface));
214 return O->getBufferIdentifier();
215 return "<null object>";
218void BasicObjectLayerMaterializationUnit::materialize(
219 std::unique_ptr<MaterializationResponsibility> R) {
220 L.
emit(std::move(R), std::move(O));
223void BasicObjectLayerMaterializationUnit::discard(
const JITDylib &JD,
224 const SymbolStringPtr &Name) {
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
@ NoDeduplicate
No deduplication is performed.
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
@ AvailableExternallyLinkage
Available for inspection, not emission.
static LLVM_ABI JITSymbolFlags fromGlobalValue(const GlobalValue &GV)
Construct a JITSymbolFlags value based on the flags of the given global value.
@ MaterializationSideEffectsOnly
A Module instance is used to store all the information related to an LLVM module.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
StringRef - Represent a constant reference to a string, i.e.
BasicIRLayerMaterializationUnit(IRLayer &L, const IRSymbolMapper::ManglingOptions &MO, ThreadSafeModule TSM)
static Expected< std::unique_ptr< BasicObjectLayerMaterializationUnit > > Create(ObjectLayer &L, std::unique_ptr< MemoryBuffer > O)
Create using the default object interface builder function.
BasicObjectLayerMaterializationUnit(ObjectLayer &L, std::unique_ptr< MemoryBuffer > O, Interface I)
StringRef getName() const override
Return the buffer's identifier as the name for this MaterializationUnit.
An ExecutionSession represents a running JIT program.
SymbolStringPtr intern(StringRef SymName)
Add a symbol name to the SymbolStringPool and return a pointer to it.
decltype(auto) runSessionLocked(Func &&F)
Run the given lambda with the session mutex locked.
Interface for layers that accept LLVM IR.
virtual void emit(std::unique_ptr< MaterializationResponsibility > R, ThreadSafeModule TSM)=0
Emit should materialize the given IR.
virtual Error add(ResourceTrackerSP RT, ThreadSafeModule TSM)
Add a MaterializatinoUnit representing the given IR to the JITDylib targeted by the given tracker.
const IRSymbolMapper::ManglingOptions *& getManglingOptions() const
Get the mangling options for this layer.
bool getCloneToNewContextOnEmit() const
Returns the current value of the CloneToNewContextOnEmit flag.
StringRef getName() const override
Return the ModuleIdentifier as the name for this MaterializationUnit.
SymbolNameToDefinitionMap SymbolToDefinition
IRMaterializationUnit(ExecutionSession &ES, const IRSymbolMapper::ManglingOptions &MO, ThreadSafeModule TSM)
Create an IRMaterializationLayer.
std::map< SymbolStringPtr, GlobalValue * > SymbolNameToDefinitionMap
Represents a JIT'd dynamic library.
Error define(std::unique_ptr< MaterializationUnitType > &&MU, ResourceTrackerSP RT=nullptr)
Define all symbols provided by the materialization unit to be part of this JITDylib.
ExecutionSession & getExecutionSession() const
Get a reference to the ExecutionSession for this JITDylib.
Mangles symbol names then uniques them in the context of an ExecutionSession.
MaterializationUnit(Interface I)
SymbolStringPtr InitSymbol
SymbolFlagsMap SymbolFlags
friend class ExecutionSession
Interface for Layers that accept object files.
ObjectLayer(ExecutionSession &ES)
virtual void emit(std::unique_ptr< MaterializationResponsibility > R, std::unique_ptr< MemoryBuffer > O)=0
Emit should materialize the given IR.
virtual Error add(ResourceTrackerSP RT, std::unique_ptr< MemoryBuffer > O, MaterializationUnit::Interface I)
Adds a MaterializationUnit for the object file in the given memory buffer to the JITDylib for the giv...
ExecutionSession & getExecutionSession()
Returns the execution session for this layer.
Pointer to a pooled string representing a symbol name.
An LLVM Module together with a shared ThreadSafeContext.
Module * getModuleUnlocked()
Get a raw pointer to the contained module without locking the context.
decltype(auto) withModuleDo(Func &&F)
Locks the associated ThreadSafeContext and calls the given function on the contained Module.
A raw_ostream that writes to an std::string.
IntrusiveRefCntPtr< ResourceTracker > ResourceTrackerSP
iterator_range< StaticInitGVIterator > getStaticInitGVs(Module &M)
Create an iterator range over the GlobalValues that contribute to static initialization.
LLVM_ABI Expected< MaterializationUnit::Interface > getObjectFileInterface(ExecutionSession &ES, MemoryBufferRef ObjBuffer)
Returns a MaterializationUnit::Interface for the object file contained in the given buffer,...
LLVM_ABI ThreadSafeModule cloneToNewContext(const ThreadSafeModule &TSMW, GVPredicate ShouldCloneDef=GVPredicate(), GVModifier UpdateClonedDefSource=GVModifier())
Clones the given module on to a new context.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Implement std::hash so that hash_code can be used in STL containers.