LLVM: lib/ExecutionEngine/Orc/Layer.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
10
16
17#define DEBUG_TYPE "orc"
18
19namespace llvm {
20namespace orc {
21
23
25 assert(RT && "RT can not be null");
26 auto &JD = RT->getJITDylib();
27 return JD.define(std::make_unique(
29 std::move(RT));
30}
31
36
37 assert(this->TSM && "Module must not be null");
38
41 for (auto &G : M.global_values()) {
42
43
44 if (.hasName() || G.isDeclaration() || G.hasLocalLinkage() ||
45 G.hasAvailableExternallyLinkage() || G.hasAppendingLinkage())
46 continue;
47
48
49
52
54
55 auto EmuTLSV = Mangle(("__emutls_v." + GV.getName()).str());
58
59
60
61 if (GV.hasInitializer()) {
62 const auto *InitVal = GV.getInitializer();
63
64
66 continue;
68 if (InitIntValue && InitIntValue->isZero())
69 continue;
70
71 auto EmuTLST = Mangle(("__emutls_t." + GV.getName()).str());
73 }
74 continue;
75 }
76
77
78 auto MangledName = Mangle(G.getName());
81 if (G.getComdat() &&
85 }
86
87
89 size_t Counter = 0;
90
91 do {
92 std::string InitSymbolName;
94 << "$." << M.getModuleIdentifier() << ".__inits." << Counter++;
97
99 }
100 });
101}
102
108
111 return TSM.withModuleDo(
112 [](const Module &M) -> StringRef { return M.getModuleIdentifier(); });
113 return "";
114}
115
116void IRMaterializationUnit::discard(const JITDylib &JD,
119 dbgs() << "In " << JD.getName() << " discarding " << *Name << " from MU@"
120 << this << " (" << getName() << ")\n";
121 }););
122
125 "Symbol not provided by this MU, or previously discarded");
126 assert(->second->isDeclaration() &&
127 "Discard should only apply to definitions");
129
130
132 GO->setComdat(nullptr);
134}
135
140
141void BasicIRLayerMaterializationUnit::materialize(
142 std::unique_ptr R) {
143
144
145
147
148
151
152#ifndef NDEBUG
153 auto &ES = R->getTargetJITDylib().getExecutionSession();
154 auto &N = R->getTargetJITDylib().getName();
155#endif
156
158 [&]() { dbgs() << "Emitting, for " << N << ", " << *this << "\n"; }););
159 L.emit(std::move(R), std::move(TSM));
160 LLVM_DEBUG(ES.runSessionLocked([&]() {
161 dbgs() << "Finished emitting, for " << N << ", " << *this << "\n";
162 }););
163}
166
168
170
173 assert(RT && "RT can not be null");
174 auto &JD = RT->getJITDylib();
175 return JD.define(std::make_unique(
176 *this, std::move(O), std::move(I)),
177 std::move(RT));
178}
179
182 if ()
183 return I.takeError();
184 return add(std::move(RT), std::move(O), std::move(*I));
185}
186
189 if ()
190 return I.takeError();
191 return add(JD, std::move(O), std::move(*I));
192}
193
196 std::unique_ptr O) {
197
198 auto ObjInterface =
200
201 if (!ObjInterface)
202 return ObjInterface.takeError();
203
204 return std::make_unique(
205 L, std::move(O), std::move(*ObjInterface));
206}
207
211
213 if (O)
214 return O->getBufferIdentifier();
215 return "";
216}
217
218void BasicObjectLayerMaterializationUnit::materialize(
219 std::unique_ptr R) {
220 L.emit(std::move(R), std::move(O));
221}
222
223void BasicObjectLayerMaterializationUnit::discard(const JITDylib &JD,
224 const SymbolStringPtr &Name) {
225
226
227}
228
229}
230}
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)
Definition Layer.cpp:136
static Expected< std::unique_ptr< BasicObjectLayerMaterializationUnit > > Create(ObjectLayer &L, std::unique_ptr< MemoryBuffer > O)
Create using the default object interface builder function.
Definition Layer.cpp:195
BasicObjectLayerMaterializationUnit(ObjectLayer &L, std::unique_ptr< MemoryBuffer > O, Interface I)
Definition Layer.cpp:208
StringRef getName() const override
Return the buffer's identifier as the name for this MaterializationUnit.
Definition Layer.cpp:212
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.
Definition Layer.cpp:24
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.
Definition Layer.cpp:109
SymbolNameToDefinitionMap SymbolToDefinition
IRMaterializationUnit(ExecutionSession &ES, const IRSymbolMapper::ManglingOptions &MO, ThreadSafeModule TSM)
Create an IRMaterializationLayer.
Definition Layer.cpp:32
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)
Definition Layer.cpp:167
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...
Definition Layer.cpp:171
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 - Return the argument parameter cast to the specified type.
bool isa(const From &Val)
isa - 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 - Return the argument parameter cast to the specified type.
Implement std::hash so that hash_code can be used in STL containers.