diff options
Diffstat (limited to 'llvm/lib/ExecutionEngine/Orc')
-rw-r--r-- | llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp | 25 | ||||
-rw-r--r-- | llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp | 6 | ||||
-rw-r--r-- | llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp | 13 | ||||
-rw-r--r-- | llvm/lib/ExecutionEngine/Orc/LLJIT.cpp | 2 |
4 files changed, 38 insertions, 8 deletions
diff --git a/llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp b/llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp index 368969b7a57..ae1c7e84259 100644 --- a/llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp +++ b/llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp @@ -134,10 +134,7 @@ void CompileOnDemandLayer2::emit(MaterializationResponsibility R, VModuleKey K, SymbolAliasMap NonCallables; SymbolAliasMap Callables; for (auto &GV : M.global_values()) { - assert(GV.hasName() && !GV.hasLocalLinkage() && - "GlobalValues must have been promoted before adding to " - "CompileOnDemandLayer"); - if (GV.isDeclaration() || GV.hasAppendingLinkage()) + if (GV.isDeclaration() || GV.hasLocalLinkage() || GV.hasAppendingLinkage()) continue; auto Name = Mangle(GV.getName()); @@ -259,6 +256,25 @@ void CompileOnDemandLayer2::emitPartition( return; } + // Ok -- we actually need to partition the symbols. Promote the symbol + // linkages/names. + // FIXME: We apply this once per partitioning. It's safe, but overkill. + { + auto PromotedGlobals = PromoteSymbols(*TSM.getModule()); + if (!PromotedGlobals.empty()) { + MangleAndInterner Mangle(ES, TSM.getModule()->getDataLayout()); + SymbolFlagsMap SymbolFlags; + for (auto &GV : PromotedGlobals) + SymbolFlags[Mangle(GV->getName())] = + JITSymbolFlags::fromGlobalValue(*GV); + if (auto Err = R.defineMaterializing(SymbolFlags)) { + ES.reportError(std::move(Err)); + R.failMaterialization(); + return; + } + } + } + expandPartition(*GVsToExtract); // Extract the requested partiton (plus any necessary aliases) and @@ -268,7 +284,6 @@ void CompileOnDemandLayer2::emitPartition( }; auto ExtractedTSM = extractSubModule(TSM, ".submodule", ShouldExtract); - R.replace(llvm::make_unique<PartitioningIRMaterializationUnit>( ES, std::move(TSM), *this)); diff --git a/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp b/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp index 29c3f4e5636..47cb273ee12 100644 --- a/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp +++ b/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp @@ -99,6 +99,12 @@ void CtorDtorRunner2::add(iterator_range<CtorDtorIterator> CtorDtors) { assert(CtorDtor.Func && CtorDtor.Func->hasName() && "Ctor/Dtor function must be named to be runnable under the JIT"); + // FIXME: Maybe use a symbol promoter here instead. + if (CtorDtor.Func->hasLocalLinkage()) { + CtorDtor.Func->setLinkage(GlobalValue::ExternalLinkage); + CtorDtor.Func->setVisibility(GlobalValue::HiddenVisibility); + } + if (CtorDtor.Data && cast<GlobalValue>(CtorDtor.Data)->isDeclaration()) { dbgs() << " Skipping because why now?\n"; continue; diff --git a/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp b/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp index 0acc5db76f4..d7fd57b6e53 100644 --- a/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp +++ b/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp @@ -248,8 +248,11 @@ void makeStub(Function &F, Value &ImplPointer) { Builder.CreateRet(Call); } -void SymbolLinkagePromoter::operator()(Module &M) { +std::vector<GlobalValue *> SymbolLinkagePromoter::operator()(Module &M) { + std::vector<GlobalValue *> PromotedGlobals; + for (auto &GV : M.global_values()) { + bool Promoted = true; // Rename if necessary. if (!GV.hasName()) @@ -258,13 +261,21 @@ void SymbolLinkagePromoter::operator()(Module &M) { GV.setName("__" + GV.getName().substr(1) + "." + Twine(NextId++)); else if (GV.hasLocalLinkage()) GV.setName("__orc_lcl." + GV.getName() + "." + Twine(NextId++)); + else + Promoted = false; if (GV.hasLocalLinkage()) { GV.setLinkage(GlobalValue::ExternalLinkage); GV.setVisibility(GlobalValue::HiddenVisibility); + Promoted = true; } GV.setUnnamedAddr(GlobalValue::UnnamedAddr::None); + + if (Promoted) + PromotedGlobals.push_back(&GV); } + + return PromotedGlobals; } Function* cloneFunctionDecl(Module &Dst, const Function &F, diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp index 89a302ca02f..47baa45a8aa 100644 --- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp +++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp @@ -185,8 +185,6 @@ Error LLLazyJIT::addLazyIRModule(JITDylib &JD, ThreadSafeModule TSM) { if (auto Err = applyDataLayout(*TSM.getModule())) return Err; - PromoteSymbols(*TSM.getModule()); - recordCtorDtors(*TSM.getModule()); auto K = ES->allocateVModule(); |