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())
50 if (G.isThreadLocal() && MO.EmulatedTLS) {
51 auto &GV = cast<GlobalVariable>(G);
53 auto Flags = JITSymbolFlags::fromGlobalValue(GV);
55 auto EmuTLSV = Mangle((
"__emutls_v." + GV.getName()).str());
56 SymbolFlags[EmuTLSV] = Flags;
57 SymbolToDefinition[EmuTLSV] = &GV;
61 if (GV.hasInitializer()) {
62 const auto *InitVal = GV.getInitializer();
65 if (isa<ConstantAggregateZero>(InitVal))
67 const auto *InitIntValue = dyn_cast<ConstantInt>(InitVal);
68 if (InitIntValue && InitIntValue->isZero())
71 auto EmuTLST = Mangle((
"__emutls_t." + GV.getName()).str());
72 SymbolFlags[EmuTLST] = Flags;
78 auto MangledName = Mangle(
G.getName());
91 std::string InitSymbolName;
93 <<
"$." << M.getModuleIdentifier() <<
".__inits." << Counter++;
102IRMaterializationUnit::IRMaterializationUnit(
106 SymbolToDefinition(
std::
move(SymbolToDefinition)) {}
112 return "<null module>";
115void IRMaterializationUnit::discard(
const JITDylib &JD,
118 dbgs() <<
"In " << JD.getName() <<
" discarding " << *Name <<
" from MU@"
119 << this <<
" (" << getName() <<
")\n";
124 "Symbol not provided by this MU, or previously discarded");
125 assert(!
I->second->isDeclaration() &&
126 "Discard should only apply to definitions");
130 if (
auto *GO = dyn_cast<GlobalObject>(
I->second))
131 GO->setComdat(
nullptr);
140void BasicIRLayerMaterializationUnit::materialize(
141 std::unique_ptr<MaterializationResponsibility> R) {
152 auto &ES = R->getTargetJITDylib().getExecutionSession();
153 auto &
N = R->getTargetJITDylib().getName();
157 [&]() { dbgs() <<
"Emitting, for " << N <<
", " << *this <<
"\n"; }););
158 L.
emit(std::move(R), std::move(
TSM));
160 dbgs() <<
"Finished emitting, for " << N <<
", " << *this <<
"\n";
172 assert(RT &&
"RT can not be null");
173 auto &JD = RT->getJITDylib();
174 return JD.
define(std::make_unique<BasicObjectLayerMaterializationUnit>(
175 *
this, std::move(O), std::move(
I)),
182 return I.takeError();
183 return add(std::move(RT), std::move(O), std::move(*
I));
189 return I.takeError();
190 return add(JD, std::move(O), std::move(*
I));
195 std::unique_ptr<MemoryBuffer> O) {
201 return ObjInterface.takeError();
203 return std::make_unique<BasicObjectLayerMaterializationUnit>(
204 L, std::move(O), std::move(*ObjInterface));
213 return O->getBufferIdentifier();
214 return "<null object>";
217void BasicObjectLayerMaterializationUnit::materialize(
218 std::unique_ptr<MaterializationResponsibility> R) {
219 L.
emit(std::move(R), std::move(O));
222void BasicObjectLayerMaterializationUnit::discard(
const JITDylib &JD,
223 const SymbolStringPtr &
Name) {
This file contains the declarations for the subclasses of Constant, which represent the different fla...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
@ NoDeduplicate
No deduplication is performed.
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
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 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.
IRMaterializationUnit is a convenient base class for MaterializationUnits wrapping LLVM IR.
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.
A MaterializationUnit represents a set of symbol definitions that can be materialized as a group,...
SymbolStringPtr InitSymbol
SymbolFlagsMap SymbolFlags
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.
iterator_range< StaticInitGVIterator > getStaticInitGVs(Module &M)
Create an iterator range over the GlobalValues that contribute to static initialization.
Expected< MaterializationUnit::Interface > getObjectFileInterface(ExecutionSession &ES, MemoryBufferRef ObjBuffer)
Returns a MaterializationUnit::Interface for the object file contained in the given buffer,...
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.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.