14 #define DEBUG_TYPE "orc" 23 return JD.
define(llvm::make_unique<BasicIRLayerMaterializationUnit>(
24 *
this, std::move(K), std::move(TSM)));
31 assert(this->TSM &&
"Module must not be null");
35 if (
G.hasName() && !
G.isDeclaration() && !
G.hasLocalLinkage() &&
36 !
G.hasAvailableExternallyLinkage() && !
G.hasAppendingLinkage()) {
37 auto MangledName = Mangle(
G.getName());
48 TSM(
std::move(TSM)), SymbolToDefinition(
std::move(SymbolToDefinition)) {}
53 return "<null module>";
56 void IRMaterializationUnit::discard(
const JITDylib &JD,
59 dbgs() <<
"In " << JD.
getName() <<
" discarding " << *Name <<
" from MU@" 60 <<
this <<
" (" <<
getName() <<
")\n";
65 "Symbol not provided by this MU, or previously discarded");
66 assert(!I->second->isDeclaration() &&
67 "Discard should only apply to definitions");
76 L(L), K(
std::move(K)) {}
78 void BasicIRLayerMaterializationUnit::materialize(
95 dbgs() <<
"Emitting, for " << R.getTargetJITDylib().getName() <<
", " 98 L.
emit(std::move(R), std::move(
TSM));
100 dbgs() <<
"Finished emitting, for " << R.getTargetJITDylib().getName()
101 <<
", " << *this <<
"\n";
114 return ObjMU.takeError();
115 return JD.
define(std::move(*ObjMU));
120 std::unique_ptr<MemoryBuffer>
O) {
125 return SymbolFlags.takeError();
127 return std::unique_ptr<BasicObjectLayerMaterializationUnit>(
129 std::move(*SymbolFlags)));
140 return O->getBufferIdentifier();
141 return "<null object>";
144 void BasicObjectLayerMaterializationUnit::materialize(
146 L.
emit(std::move(R), std::move(O));
149 void BasicObjectLayerMaterializationUnit::discard(
const JITDylib &JD,
160 return Obj.takeError();
163 for (
auto &Sym : (*Obj)->symbols()) {
172 auto Name = Sym.getName();
174 return Name.takeError();
175 auto InternedName = ES.
intern(*Name);
178 return SymFlags.takeError();
179 SymbolFlags[InternedName] = std::move(*SymFlags);
bool getCloneToNewContextOnEmit() const
Returns the current value of the CloneToNewContextOnEmit flag.
IRLayer(ExecutionSession &ES)
static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
static JITSymbolFlags fromGlobalValue(const GlobalValue &GV)
Construct a JITSymbolFlags value based on the flags of the given global value.
This class represents lattice values for constants.
StringRef getName() const override
Return the ModuleIdentifier as the name for this MaterializationUnit.
SymbolNameToDefinitionMap SymbolToDefinition
Available for inspection, not emission.
static Expected< JITSymbolFlags > fromObjectSymbol(const object::SymbolRef &Symbol)
Construct a JITSymbolFlags value based on the flags of the given libobject symbol.
StringRef getName() const override
Return the buffer's identifier as the name for this MaterializationUnit.
uint64_t VModuleKey
VModuleKey provides a unique identifier (allocated and managed by ExecutionSessions) for a module add...
Materializes the given object file (represented by a MemoryBuffer instance) by calling 'emit' on the ...
IRMaterializationUnit(ExecutionSession &ES, ThreadSafeModule TSM, VModuleKey K)
Create an IRMaterializationLayer.
amdgpu Simplify well known AMD library false Value Value const Twine & Name
SymbolStringPtr intern(StringRef SymName)
Add a symbol name to the SymbolStringPool and return a pointer to it.
BasicObjectLayerMaterializationUnit(ObjectLayer &L, VModuleKey K, std::unique_ptr< MemoryBuffer > O, SymbolFlagsMap SymbolFlags)
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
SymbolFlagsMap SymbolFlags
Error define(std::unique_ptr< MaterializationUnitType > &&MU)
Define all symbols provided by the materialization unit to be part of this JITDylib.
Mangles symbol names then uniques them in the context of an ExecutionSession.
std::map< SymbolStringPtr, GlobalValue * > SymbolNameToDefinitionMap
Tagged union holding either a T or a Error.
virtual Error add(JITDylib &JD, ThreadSafeModule TSM, VModuleKey K=VModuleKey())
Adds a MaterializationUnit representing the given IR to the given JITDylib.
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
IRMaterializationUnit is a convenient base class for MaterializationUnits wrapping LLVM IR...
ExecutionSession & getExecutionSession()
Returns the execution session for this layer.
JITDylib & getTargetJITDylib() const
Returns the target JITDylib that these symbols are being materialized into.
ExecutionSession & getExecutionSession() const
Get a reference to the ExecutionSession for this JITDylib.
Pointer to a pooled string representing a symbol name.
virtual void emit(MaterializationResponsibility R, ThreadSafeModule TSM)=0
Emit should materialize the given IR.
Module * getModule()
Get the module wrapped by this ThreadSafeModule.
Expected< SymbolFlagsMap > getObjectSymbolFlags(ExecutionSession &ES, MemoryBufferRef ObjBuffer)
Returns a SymbolFlagsMap for the object file represented by the given buffer, or an error if the buff...
ObjectLayer(ExecutionSession &ES)
An LLVM Module together with a shared ThreadSafeContext.
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
virtual void emit(MaterializationResponsibility R, std::unique_ptr< MemoryBuffer > O)=0
Emit should materialize the given IR.
virtual Error add(JITDylib &JD, std::unique_ptr< MemoryBuffer > O, VModuleKey K=VModuleKey())
Adds a MaterializationUnit representing the given IR to the given JITDylib.
Interface for layers that accept LLVM IR.
A MaterializationUnit represents a set of symbol definitions that can be materialized as a group...
ThreadSafeContext::Lock getContextLock()
Take out a lock on the ThreadSafeContext for this module.
An ExecutionSession represents a running JIT program.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
BasicIRLayerMaterializationUnit(IRLayer &L, VModuleKey K, ThreadSafeModule TSM)
static Expected< std::unique_ptr< BasicObjectLayerMaterializationUnit > > Create(ObjectLayer &L, VModuleKey K, std::unique_ptr< MemoryBuffer > O)
auto runSessionLocked(Func &&F) -> decltype(F())
Run the given lambda with the session mutex locked.
const std::string & getName() const
Get the name for this JITDylib.
ThreadSafeModule cloneToNewContext(ThreadSafeModule &TSMW, GVPredicate ShouldCloneDef=GVPredicate(), GVModifier UpdateClonedDefSource=GVModifier())
Clones the given module on to a new context.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Lightweight error class with error context and mandatory checking.
Interface for Layers that accept object files.
StringRef - Represent a constant reference to a string, i.e.
iterator_range< global_value_iterator > global_values()
A symbol table that supports asynchoronous symbol queries.