14 #define DEBUG_TYPE "orc" 22 return JD.
define(std::make_unique<BasicIRLayerMaterializationUnit>(
31 assert(this->TSM &&
"Module must not be null");
37 if (!
G.hasName() ||
G.isDeclaration() ||
G.hasLocalLinkage() ||
38 G.hasAvailableExternallyLinkage() ||
G.hasAppendingLinkage())
44 auto &GV = cast<GlobalVariable>(
G);
48 auto EmuTLSV = Mangle((
"__emutls_v." + GV.getName()).str());
54 if (GV.hasInitializer()) {
55 const auto *InitVal = GV.getInitializer();
58 if (isa<ConstantAggregateZero>(InitVal))
61 if (InitIntValue && InitIntValue->isZero())
64 auto EmuTLST = Mangle((
"__emutls_t." + GV.getName()).str());
65 SymbolFlags[EmuTLST] = Flags;
71 auto MangledName = Mangle(
G.getName());
82 TSM(
std::move(TSM)), SymbolToDefinition(
std::move(SymbolToDefinition)) {}
88 return "<null module>";
91 void IRMaterializationUnit::discard(
const JITDylib &JD,
94 dbgs() <<
"In " << JD.
getName() <<
" discarding " << *Name <<
" from MU@" 95 <<
this <<
" (" <<
getName() <<
")\n";
100 "Symbol not provided by this MU, or previously discarded");
101 assert(!I->second->isDeclaration() &&
102 "Discard should only apply to definitions");
111 L(L), K(
std::move(K)) {}
113 void BasicIRLayerMaterializationUnit::materialize(
130 [&]() { dbgs() <<
"Emitting, for " << N <<
", " << *this <<
"\n"; }););
131 L.
emit(std::move(R), std::move(
TSM));
133 dbgs() <<
"Finished emitting, for " << N <<
", " << *this <<
"\n";
146 return ObjMU.takeError();
147 return JD.
define(std::move(*ObjMU));
152 std::unique_ptr<MemoryBuffer>
O) {
159 return std::unique_ptr<BasicObjectLayerMaterializationUnit>(
172 return O->getBufferIdentifier();
173 return "<null object>";
176 void BasicObjectLayerMaterializationUnit::materialize(
178 L.
emit(std::move(R), std::move(O));
181 void BasicObjectLayerMaterializationUnit::discard(
const JITDylib &JD,
192 return Obj.takeError();
195 for (
auto &Sym : (*Obj)->symbols()) {
204 auto Name = Sym.getName();
206 return Name.takeError();
207 auto InternedName = ES.
intern(*Name);
210 return SymFlags.takeError();
211 SymbolFlags[InternedName] = std::move(*SymFlags);
bool getCloneToNewContextOnEmit() const
Returns the current value of the CloneToNewContextOnEmit flag.
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.
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
StringRef getName() const override
Return the ModuleIdentifier as the name for this MaterializationUnit.
SymbolNameToDefinitionMap SymbolToDefinition
Available for inspection, not emission.
auto withModuleDo(Func &&F) -> decltype(F(std::declval< Module &>()))
Locks the associated ThreadSafeContext and calls the given function on the contained Module...
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.
Materializes the given object file (represented by a MemoryBuffer instance) by calling 'emit' on the ...
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.
const IRMaterializationUnit::ManglingOptions *& getManglingOptions() const
Get the mangling options for this layer.
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.
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)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
IRMaterializationUnit(ExecutionSession &ES, const ManglingOptions &MO, ThreadSafeModule TSM, VModuleKey K)
Create an IRMaterializationLayer.
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...
This is the shared class of boolean and integer constants.
An ExecutionSession represents a running JIT program.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Module * getModuleUnlocked()
Get a raw pointer to the contained module without locking the context.
static Expected< std::unique_ptr< BasicObjectLayerMaterializationUnit > > Create(ObjectLayer &L, VModuleKey K, std::unique_ptr< MemoryBuffer > O)
uint8_t uint64_t VModuleKey
VModuleKey provides a unique identifier (allocated and managed by ExecutionSessions) for a module add...
BasicIRLayerMaterializationUnit(IRLayer &L, const ManglingOptions &MO, ThreadSafeModule TSM, VModuleKey K)
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.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
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.
A symbol table that supports asynchoronous symbol queries.
iterator_range< global_value_iterator > global_values()