28 F.setPersonalityFn(
nullptr);
36 assert(
A.hasName() &&
"Anonymous alias?");
38 std::string AliasName = std::string(
A.getName());
42 A.replaceAllUsesWith(
F);
44 F->setName(AliasName);
48 A.replaceAllUsesWith(
G);
50 G->setName(AliasName);
58 NewTSM.withModuleDo([&](
Module &M) {
59 M.setModuleIdentifier((M.getModuleIdentifier() + Suffix).str());
84 void materialize(std::unique_ptr<MaterializationResponsibility> R)
override {
85 Parent.emitPartition(std::move(R), std::move(
TSM),
93 "ExtractingIRMaterializationUnit");
106 this->Partition = Partition;
109std::optional<IRPartitionLayer::GlobalValueSet>
111 return std::move(Requested);
114std::optional<IRPartitionLayer::GlobalValueSet>
121 assert(TSM &&
"Null module");
130 if (
auto Err = R->replace(std::make_unique<PartitioningIRMaterializationUnit>(
132 ES.reportError(std::move(Err));
133 R->failMaterialization();
138void IRPartitionLayer::cleanUpModule(
Module &M) {
139 for (
auto &
F : M.functions()) {
140 if (
F.isDeclaration())
143 if (
F.hasAvailableExternallyLinkage()) {
145 F.setPersonalityFn(
nullptr);
151void IRPartitionLayer::expandPartition(GlobalValueSet &Partition) {
158 assert(!Partition.empty() &&
"Unexpected empty partition");
160 const Module &
M = *(*Partition.begin())->getParent();
161 bool ContainsGlobalVariables =
false;
162 std::vector<const GlobalValue *> GVsToAdd;
164 for (
const auto *GV : Partition)
169 ContainsGlobalVariables =
true;
171 for (
auto &
A :
M.aliases())
173 GVsToAdd.push_back(&
A);
175 if (ContainsGlobalVariables)
176 for (
auto &
G :
M.globals())
177 GVsToAdd.push_back(&
G);
179 for (
const auto *GV : GVsToAdd)
180 Partition.insert(GV);
183void IRPartitionLayer::emitPartition(
194 for (
auto &Name :
R->getRequestedSymbols()) {
195 if (Name ==
R->getInitializerSymbol())
198 RequestedGVs.insert(&GV);
201 assert(Defs.count(Name) &&
"No definition for symbol");
202 RequestedGVs.insert(Defs[Name]);
214 if (GVsToExtract == std::nullopt) {
216 BaseLayer.emit(std::move(R), std::move(TSM));
221 if (GVsToExtract->empty()) {
223 R->replace(std::make_unique<PartitioningIRMaterializationUnit>(
225 MaterializationUnit::Interface(
R->getSymbols(),
226 R->getInitializerSymbol()),
227 std::move(Defs), *
this))) {
229 R->failMaterialization();
243 -> Expected<ThreadSafeModule> {
244 auto PromotedGlobals = PromoteSymbols(M);
245 if (!PromotedGlobals.empty()) {
247 MangleAndInterner
Mangle(ES,
M.getDataLayout());
252 if (
auto Err =
R->defineMaterializing(SymbolFlags))
253 return std::move(Err);
256 expandPartition(*GVsToExtract);
259 std::string SubModuleName;
261 std::vector<const GlobalValue *> HashGVs;
262 HashGVs.reserve(GVsToExtract->size());
268 for (
const auto *GV : HashGVs) {
269 assert(GV->hasName() &&
"All GVs to extract should be named by now");
270 auto GVName = GV->getName();
273 raw_string_ostream(SubModuleName)
275 <<
formatv(
sizeof(
size_t) == 8 ?
"{0:x16}" :
"{0:x8}",
276 static_cast<size_t>(HC))
282 auto ShouldExtract = [&](
const GlobalValue &GV) ->
bool {
283 return GVsToExtract->count(&GV);
290 ES.reportError(ExtractedTSM.takeError());
291 R->failMaterialization();
295 if (
auto Err =
R->replace(std::make_unique<PartitioningIRMaterializationUnit>(
297 ES.reportError(std::move(Err));
298 R->failMaterialization();
301 BaseLayer.emit(std::move(R), std::move(*ExtractedTSM));
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static ThreadSafeModule extractSubModule(ThreadSafeModule &TSM, StringRef Suffix, GVPredicate ShouldExtract)
Machine Check Debug Module
This is an important base class in LLVM.
@ ExternalLinkage
Externally visible function.
A Module instance is used to store all the information related to an LLVM module.
StringRef - Represent a constant reference to a string, i.e.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
An ExecutionSession represents a running JIT program.
void reportError(Error Err)
Report a error for this execution session.
IRLayer(ExecutionSession &ES, const IRSymbolMapper::ManglingOptions *&MO)
ExecutionSession & getExecutionSession()
Returns the ExecutionSession for this layer.
const IRSymbolMapper::ManglingOptions *& getManglingOptions() const
Get the mangling options for this layer.
SymbolNameToDefinitionMap SymbolToDefinition
IRMaterializationUnit(ExecutionSession &ES, const IRSymbolMapper::ManglingOptions &MO, ThreadSafeModule TSM)
Create an IRMaterializationLayer.
std::map< SymbolStringPtr, GlobalValue * > SymbolNameToDefinitionMap
A layer that breaks up IR modules into smaller submodules that only contains looked up symbols.
std::function< std::optional< GlobalValueSet >(GlobalValueSet Requested)> PartitionFunction
Partitioning function.
void emit(std::unique_ptr< MaterializationResponsibility > R, ThreadSafeModule TSM) override
Emits the given module.
static std::optional< GlobalValueSet > compileWholeModule(GlobalValueSet Requested)
Off-the-shelf partitioning which compiles whole modules whenever any symbol in them is requested.
std::set< const GlobalValue * > GlobalValueSet
IRPartitionLayer(ExecutionSession &ES, IRLayer &BaseLayer)
Construct a IRPartitionLayer.
void setPartitionFunction(PartitionFunction Partition)
Sets the partition function.
static std::optional< GlobalValueSet > compileRequested(GlobalValueSet Requested)
Off-the-shelf partitioning which compiles all requested symbols (usually a single function at a time)...
static LLVM_ABI void add(ExecutionSession &ES, const ManglingOptions &MO, ArrayRef< GlobalValue * > GVs, SymbolFlagsMap &SymbolFlags, SymbolNameToDefinitionMap *SymbolToDefinition=nullptr)
Add mangled symbols for the given GlobalValues to SymbolFlags.
Represents a JIT'd dynamic library.
PartitioningIRMaterializationUnit(ThreadSafeModule TSM, Interface I, SymbolNameToDefinitionMap SymbolToDefinition, IRPartitionLayer &Parent)
PartitioningIRMaterializationUnit(ExecutionSession &ES, const IRSymbolMapper::ManglingOptions &MO, ThreadSafeModule TSM, IRPartitionLayer &Parent)
Pointer to a pooled string representing a symbol name.
An LLVM Module together with a shared ThreadSafeContext.
decltype(auto) withModuleDo(Func &&F)
Locks the associated ThreadSafeContext and calls the given function on the contained Module.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::function< bool(const GlobalValue &)> GVPredicate
iterator_range< StaticInitGVIterator > getStaticInitGVs(Module &M)
Create an iterator range over the GlobalValues that contribute to static initialization.
LLVM_ABI GlobalVariable * cloneGlobalVariableDecl(Module &Dst, const GlobalVariable &GV, ValueToValueMapTy *VMap=nullptr)
Clone a global variable declaration into a new module.
LLVM_ABI Function * cloneFunctionDecl(Module &Dst, const Function &F, ValueToValueMapTy *VMap=nullptr)
Clone a function declaration into a new module.
LLVM_ABI ThreadSafeModule cloneToNewContext(const ThreadSafeModule &TSMW, GVPredicate ShouldCloneDef=GVPredicate(), GVModifier UpdateClonedDefSource=GVModifier())
Clones the given module on to a new context.
DenseMap< SymbolStringPtr, JITSymbolFlags > SymbolFlagsMap
A map from symbol names (as SymbolStringPtrs) to JITSymbolFlags.
This is an optimization pass for GlobalISel generic memory operations.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
void sort(IteratorTy Start, IteratorTy End)
bool isa(const From &Val)
isa<X> - 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<X> - Return the argument parameter cast to the specified type.
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
Implement std::hash so that hash_code can be used in STL containers.