Go to the documentation of this file.
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());
88 std::string InitSymbolName;
90 <<
"$." <<
M.getModuleIdentifier() <<
".__inits." << Counter++;
99 IRMaterializationUnit::IRMaterializationUnit(
103 SymbolToDefinition(
std::
move(SymbolToDefinition)) {}
109 return "<null module>";
112 void IRMaterializationUnit::discard(
const JITDylib &JD,
115 dbgs() <<
"In " << JD.getName() <<
" discarding " << *Name <<
" from MU@"
116 << this <<
" (" << getName() <<
")\n";
121 "Symbol not provided by this MU, or previously discarded");
122 assert(!
I->second->isDeclaration() &&
123 "Discard should only apply to definitions");
133 void BasicIRLayerMaterializationUnit::materialize(
134 std::unique_ptr<MaterializationResponsibility> R) {
145 auto &ES = R->getTargetJITDylib().getExecutionSession();
146 auto &
N = R->getTargetJITDylib().getName();
150 [&]() { dbgs() <<
"Emitting, for " << N <<
", " << *this <<
"\n"; }););
153 dbgs() <<
"Finished emitting, for " << N <<
", " << *this <<
"\n";
165 assert(RT &&
"RT can not be null");
166 auto &JD = RT->getJITDylib();
167 return JD.
define(std::make_unique<BasicObjectLayerMaterializationUnit>(
175 return I.takeError();
182 return I.takeError();
188 std::unique_ptr<MemoryBuffer>
O) {
194 return ObjInterface.takeError();
196 return std::unique_ptr<BasicObjectLayerMaterializationUnit>(
207 return O->getBufferIdentifier();
208 return "<null object>";
211 void BasicObjectLayerMaterializationUnit::materialize(
212 std::unique_ptr<MaterializationResponsibility> R) {
216 void BasicObjectLayerMaterializationUnit::discard(
const JITDylib &JD,
217 const SymbolStringPtr &
Name) {
This is an optimization pass for GlobalISel generic memory operations.
Represents a JIT'd dynamic library.
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
IRMaterializationUnit is a convenient base class for MaterializationUnits wrapping LLVM IR.
A raw_ostream that writes to an std::string.
Pointer to a pooled string representing a symbol name.
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...
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
const IRSymbolMapper::ManglingOptions *& getManglingOptions() const
Get the mangling options for this layer.
Tagged union holding either a T or a Error.
Module * getModuleUnlocked()
Get a raw pointer to the contained module without locking the context.
A MaterializationUnit represents a set of symbol definitions that can be materialized as a group,...
@ MaterializationSideEffectsOnly
StringRef getName() const override
Return the buffer's identifier as the name for this MaterializationUnit.
SymbolStringPtr intern(StringRef SymName)
Add a symbol name to the SymbolStringPool and return a pointer to it.
ExecutionSession & getExecutionSession()
Returns the execution session for this layer.
decltype(auto) runSessionLocked(Func &&F)
Run the given lambda with the session mutex locked.
Interface for Layers that accept object files.
IRMaterializationUnit(ExecutionSession &ES, const IRSymbolMapper::ManglingOptions &MO, ThreadSafeModule TSM)
Create an IRMaterializationLayer.
iterator_range< StaticInitGVIterator > getStaticInitGVs(Module &M)
Create an iterator range over the GlobalValues that contribute to static initialization.
virtual Error add(ResourceTrackerSP RT, ThreadSafeModule TSM)
Add a MaterializatinoUnit representing the given IR to the JITDylib targeted by the given tracker.
virtual void emit(std::unique_ptr< MaterializationResponsibility > R, ThreadSafeModule TSM)=0
Emit should materialize the given IR.
static Expected< std::unique_ptr< BasicObjectLayerMaterializationUnit > > Create(ObjectLayer &L, std::unique_ptr< MemoryBuffer > O)
Create using the default object interface builder function.
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
uint8_t IntrusiveRefCntPtr< ResourceTracker > ResourceTrackerSP
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
bool getCloneToNewContextOnEmit() const
Returns the current value of the CloneToNewContextOnEmit flag.
A Module instance is used to store all the information related to an LLVM module.
BasicObjectLayerMaterializationUnit(ObjectLayer &L, std::unique_ptr< MemoryBuffer > O, Interface I)
decltype(auto) withModuleDo(Func &&F)
Locks the associated ThreadSafeContext and calls the given function on the contained Module.
virtual void emit(std::unique_ptr< MaterializationResponsibility > R, std::unique_ptr< MemoryBuffer > O)=0
Emit should materialize the given IR.
StringRef - Represent a constant reference to a string, i.e.
BasicIRLayerMaterializationUnit(IRLayer &L, const IRSymbolMapper::ManglingOptions &MO, ThreadSafeModule TSM)
@ AvailableExternallyLinkage
Available for inspection, not emission.
Mangles symbol names then uniques them in the context of an ExecutionSession.
constexpr bool empty(const T &RangeOrContainer)
Test whether RangeOrContainer is empty. Similar to C++17 std::empty.
Lightweight error class with error context and mandatory checking.
An ExecutionSession represents a running JIT program.
static JITSymbolFlags fromGlobalValue(const GlobalValue &GV)
Construct a JITSymbolFlags value based on the flags of the given global value.
Error define(std::unique_ptr< MaterializationUnitType > &&MU, ResourceTrackerSP RT=nullptr)
Define all symbols provided by the materialization unit to be part of this JITDylib.
Expected< MaterializationUnit::Interface > getObjectFileInterface(ExecutionSession &ES, MemoryBufferRef ObjBuffer)
Returns a MaterializationUnit::Interface for the object file contained in the given buffer,...
ExecutionSession & getExecutionSession() const
Get a reference to the ExecutionSession for this JITDylib.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
An LLVM Module together with a shared ThreadSafeContext.
SymbolNameToDefinitionMap SymbolToDefinition
SymbolFlagsMap SymbolFlags
ObjectLayer(ExecutionSession &ES)
std::map< SymbolStringPtr, GlobalValue * > SymbolNameToDefinitionMap
StringRef getName() const override
Return the ModuleIdentifier as the name for this MaterializationUnit.
Interface for layers that accept LLVM IR.
ThreadSafeModule cloneToNewContext(const ThreadSafeModule &TSMW, GVPredicate ShouldCloneDef=GVPredicate(), GVModifier UpdateClonedDefSource=GVModifier())
Clones the given module on to a new context.
SymbolStringPtr InitSymbol