Lang Hames | 68c9b8d | 2018-06-18 18:01:43 +0000 | [diff] [blame] | 1 | //===----- CompileOnDemandLayer.cpp - Lazily emit IR on first call --------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Lang Hames | 68c9b8d | 2018-06-18 18:01:43 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h" |
| 10 | #include "llvm/IR/Mangler.h" |
| 11 | #include "llvm/IR/Module.h" |
Lang Hames | 68c9b8d | 2018-06-18 18:01:43 +0000 | [diff] [blame] | 12 | |
| 13 | using namespace llvm; |
| 14 | using namespace llvm::orc; |
| 15 | |
Lang Hames | 9844029 | 2018-09-29 23:49:57 +0000 | [diff] [blame] | 16 | static ThreadSafeModule extractSubModule(ThreadSafeModule &TSM, |
| 17 | StringRef Suffix, |
| 18 | GVPredicate ShouldExtract) { |
Lang Hames | 6a94134 | 2018-06-26 21:35:48 +0000 | [diff] [blame] | 19 | |
Lang Hames | 9844029 | 2018-09-29 23:49:57 +0000 | [diff] [blame] | 20 | auto DeleteExtractedDefs = [](GlobalValue &GV) { |
| 21 | // Bump the linkage: this global will be provided by the external module. |
| 22 | GV.setLinkage(GlobalValue::ExternalLinkage); |
Lang Hames | 6a94134 | 2018-06-26 21:35:48 +0000 | [diff] [blame] | 23 | |
Lang Hames | 9844029 | 2018-09-29 23:49:57 +0000 | [diff] [blame] | 24 | // Delete the definition in the source module. |
Lang Hames | 8d76c71 | 2018-09-26 01:24:12 +0000 | [diff] [blame] | 25 | if (isa<Function>(GV)) { |
| 26 | auto &F = cast<Function>(GV); |
| 27 | F.deleteBody(); |
| 28 | F.setPersonalityFn(nullptr); |
| 29 | } else if (isa<GlobalVariable>(GV)) { |
| 30 | cast<GlobalVariable>(GV).setInitializer(nullptr); |
Lang Hames | 9844029 | 2018-09-29 23:49:57 +0000 | [diff] [blame] | 31 | } else if (isa<GlobalAlias>(GV)) { |
| 32 | // We need to turn deleted aliases into function or variable decls based |
| 33 | // on the type of their aliasee. |
| 34 | auto &A = cast<GlobalAlias>(GV); |
| 35 | Constant *Aliasee = A.getAliasee(); |
| 36 | assert(A.hasName() && "Anonymous alias?"); |
| 37 | assert(Aliasee->hasName() && "Anonymous aliasee"); |
| 38 | std::string AliasName = A.getName(); |
| 39 | |
| 40 | if (isa<Function>(Aliasee)) { |
| 41 | auto *F = cloneFunctionDecl(*A.getParent(), *cast<Function>(Aliasee)); |
| 42 | A.replaceAllUsesWith(F); |
| 43 | A.eraseFromParent(); |
| 44 | F->setName(AliasName); |
| 45 | } else if (isa<GlobalVariable>(Aliasee)) { |
| 46 | auto *G = cloneGlobalVariableDecl(*A.getParent(), |
| 47 | *cast<GlobalVariable>(Aliasee)); |
| 48 | A.replaceAllUsesWith(G); |
| 49 | A.eraseFromParent(); |
| 50 | G->setName(AliasName); |
| 51 | } else |
| 52 | llvm_unreachable("Alias to unsupported type"); |
Lang Hames | 8d76c71 | 2018-09-26 01:24:12 +0000 | [diff] [blame] | 53 | } else |
| 54 | llvm_unreachable("Unsupported global type"); |
Lang Hames | 8d76c71 | 2018-09-26 01:24:12 +0000 | [diff] [blame] | 55 | }; |
Lang Hames | 68c9b8d | 2018-06-18 18:01:43 +0000 | [diff] [blame] | 56 | |
Lang Hames | 809e9d1 | 2019-08-02 15:21:37 +0000 | [diff] [blame] | 57 | auto NewTSM = cloneToNewContext(TSM, ShouldExtract, DeleteExtractedDefs); |
| 58 | NewTSM.withModuleDo([&](Module &M) { |
| 59 | M.setModuleIdentifier((M.getModuleIdentifier() + Suffix).str()); |
| 60 | }); |
Lang Hames | 68c9b8d | 2018-06-18 18:01:43 +0000 | [diff] [blame] | 61 | |
Lang Hames | 809e9d1 | 2019-08-02 15:21:37 +0000 | [diff] [blame] | 62 | return NewTSM; |
Lang Hames | 7bd8970 | 2018-07-05 19:01:27 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Lang Hames | 68c9b8d | 2018-06-18 18:01:43 +0000 | [diff] [blame] | 65 | namespace llvm { |
| 66 | namespace orc { |
| 67 | |
Lang Hames | 9844029 | 2018-09-29 23:49:57 +0000 | [diff] [blame] | 68 | class PartitioningIRMaterializationUnit : public IRMaterializationUnit { |
Lang Hames | 68c9b8d | 2018-06-18 18:01:43 +0000 | [diff] [blame] | 69 | public: |
Lang Hames | 9844029 | 2018-09-29 23:49:57 +0000 | [diff] [blame] | 70 | PartitioningIRMaterializationUnit(ExecutionSession &ES, ThreadSafeModule TSM, |
Lang Hames | 8b94274 | 2018-10-16 20:13:06 +0000 | [diff] [blame] | 71 | VModuleKey K, CompileOnDemandLayer &Parent) |
| 72 | : IRMaterializationUnit(ES, std::move(TSM), std::move(K)), |
| 73 | Parent(Parent) {} |
Lang Hames | 68c9b8d | 2018-06-18 18:01:43 +0000 | [diff] [blame] | 74 | |
Lang Hames | 9844029 | 2018-09-29 23:49:57 +0000 | [diff] [blame] | 75 | PartitioningIRMaterializationUnit( |
| 76 | ThreadSafeModule TSM, SymbolFlagsMap SymbolFlags, |
| 77 | SymbolNameToDefinitionMap SymbolToDefinition, |
Lang Hames | 079df9a | 2018-10-15 22:56:10 +0000 | [diff] [blame] | 78 | CompileOnDemandLayer &Parent) |
Lang Hames | 8b94274 | 2018-10-16 20:13:06 +0000 | [diff] [blame] | 79 | : IRMaterializationUnit(std::move(TSM), std::move(K), |
| 80 | std::move(SymbolFlags), |
Lang Hames | 68c9b8d | 2018-06-18 18:01:43 +0000 | [diff] [blame] | 81 | std::move(SymbolToDefinition)), |
Lang Hames | fd0c1e71 | 2018-07-20 18:31:50 +0000 | [diff] [blame] | 82 | Parent(Parent) {} |
Lang Hames | 68c9b8d | 2018-06-18 18:01:43 +0000 | [diff] [blame] | 83 | |
| 84 | private: |
| 85 | void materialize(MaterializationResponsibility R) override { |
Lang Hames | 9844029 | 2018-09-29 23:49:57 +0000 | [diff] [blame] | 86 | Parent.emitPartition(std::move(R), std::move(TSM), |
| 87 | std::move(SymbolToDefinition)); |
Lang Hames | 68c9b8d | 2018-06-18 18:01:43 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Lang Hames | cb5702c3 | 2018-10-06 23:02:06 +0000 | [diff] [blame] | 90 | void discard(const JITDylib &V, const SymbolStringPtr &Name) override { |
Lang Hames | 68c9b8d | 2018-06-18 18:01:43 +0000 | [diff] [blame] | 91 | // All original symbols were materialized by the CODLayer and should be |
| 92 | // final. The function bodies provided by M should never be overridden. |
| 93 | llvm_unreachable("Discard should never be called on an " |
| 94 | "ExtractingIRMaterializationUnit"); |
| 95 | } |
| 96 | |
Lang Hames | 7bd8970 | 2018-07-05 19:01:27 +0000 | [diff] [blame] | 97 | mutable std::mutex SourceModuleMutex; |
Lang Hames | 079df9a | 2018-10-15 22:56:10 +0000 | [diff] [blame] | 98 | CompileOnDemandLayer &Parent; |
Lang Hames | 68c9b8d | 2018-06-18 18:01:43 +0000 | [diff] [blame] | 99 | }; |
| 100 | |
Lang Hames | 079df9a | 2018-10-15 22:56:10 +0000 | [diff] [blame] | 101 | Optional<CompileOnDemandLayer::GlobalValueSet> |
| 102 | CompileOnDemandLayer::compileRequested(GlobalValueSet Requested) { |
Lang Hames | 9844029 | 2018-09-29 23:49:57 +0000 | [diff] [blame] | 103 | return std::move(Requested); |
| 104 | } |
| 105 | |
Lang Hames | 079df9a | 2018-10-15 22:56:10 +0000 | [diff] [blame] | 106 | Optional<CompileOnDemandLayer::GlobalValueSet> |
| 107 | CompileOnDemandLayer::compileWholeModule(GlobalValueSet Requested) { |
Lang Hames | 9844029 | 2018-09-29 23:49:57 +0000 | [diff] [blame] | 108 | return None; |
| 109 | } |
| 110 | |
Lang Hames | 079df9a | 2018-10-15 22:56:10 +0000 | [diff] [blame] | 111 | CompileOnDemandLayer::CompileOnDemandLayer( |
Lang Hames | d804867 | 2018-09-26 05:08:29 +0000 | [diff] [blame] | 112 | ExecutionSession &ES, IRLayer &BaseLayer, LazyCallThroughManager &LCTMgr, |
Lang Hames | 8d76c71 | 2018-09-26 01:24:12 +0000 | [diff] [blame] | 113 | IndirectStubsManagerBuilder BuildIndirectStubsManager) |
Lang Hames | d804867 | 2018-09-26 05:08:29 +0000 | [diff] [blame] | 114 | : IRLayer(ES), BaseLayer(BaseLayer), LCTMgr(LCTMgr), |
Lang Hames | 8d76c71 | 2018-09-26 01:24:12 +0000 | [diff] [blame] | 115 | BuildIndirectStubsManager(std::move(BuildIndirectStubsManager)) {} |
Lang Hames | 68c9b8d | 2018-06-18 18:01:43 +0000 | [diff] [blame] | 116 | |
Lang Hames | 079df9a | 2018-10-15 22:56:10 +0000 | [diff] [blame] | 117 | void CompileOnDemandLayer::setPartitionFunction(PartitionFunction Partition) { |
Lang Hames | 9844029 | 2018-09-29 23:49:57 +0000 | [diff] [blame] | 118 | this->Partition = std::move(Partition); |
Lang Hames | 68c9b8d | 2018-06-18 18:01:43 +0000 | [diff] [blame] | 119 | } |
| 120 | |
Praveen Velliengiri | f5c40cb | 2019-08-03 14:42:13 +0000 | [diff] [blame^] | 121 | void CompileOnDemandLayer::setImplMap(ImplSymbolMap *Imp) { |
| 122 | this->AliaseeImpls = Imp; |
| 123 | } |
Lang Hames | 8b94274 | 2018-10-16 20:13:06 +0000 | [diff] [blame] | 124 | void CompileOnDemandLayer::emit(MaterializationResponsibility R, |
| 125 | ThreadSafeModule TSM) { |
Lang Hames | 809e9d1 | 2019-08-02 15:21:37 +0000 | [diff] [blame] | 126 | assert(TSM && "Null module"); |
Lang Hames | 9844029 | 2018-09-29 23:49:57 +0000 | [diff] [blame] | 127 | |
Lang Hames | 68c9b8d | 2018-06-18 18:01:43 +0000 | [diff] [blame] | 128 | auto &ES = getExecutionSession(); |
Lang Hames | 68c9b8d | 2018-06-18 18:01:43 +0000 | [diff] [blame] | 129 | |
Lang Hames | 809e9d1 | 2019-08-02 15:21:37 +0000 | [diff] [blame] | 130 | // Sort the callables and non-callables, build re-exports and lodge the |
Lang Hames | 9844029 | 2018-09-29 23:49:57 +0000 | [diff] [blame] | 131 | // actual module with the implementation dylib. |
| 132 | auto &PDR = getPerDylibResources(R.getTargetJITDylib()); |
Lang Hames | 68c9b8d | 2018-06-18 18:01:43 +0000 | [diff] [blame] | 133 | |
Lang Hames | 9844029 | 2018-09-29 23:49:57 +0000 | [diff] [blame] | 134 | SymbolAliasMap NonCallables; |
| 135 | SymbolAliasMap Callables; |
Lang Hames | 809e9d1 | 2019-08-02 15:21:37 +0000 | [diff] [blame] | 136 | TSM.withModuleDo([&](Module &M) { |
| 137 | // First, do some cleanup on the module: |
| 138 | cleanUpModule(M); |
Lang Hames | 68c9b8d | 2018-06-18 18:01:43 +0000 | [diff] [blame] | 139 | |
Lang Hames | 809e9d1 | 2019-08-02 15:21:37 +0000 | [diff] [blame] | 140 | MangleAndInterner Mangle(ES, M.getDataLayout()); |
| 141 | for (auto &GV : M.global_values()) { |
| 142 | if (GV.isDeclaration() || GV.hasLocalLinkage() || |
| 143 | GV.hasAppendingLinkage()) |
| 144 | continue; |
| 145 | |
| 146 | auto Name = Mangle(GV.getName()); |
| 147 | auto Flags = JITSymbolFlags::fromGlobalValue(GV); |
| 148 | if (Flags.isCallable()) |
| 149 | Callables[Name] = SymbolAliasMapEntry(Name, Flags); |
| 150 | else |
| 151 | NonCallables[Name] = SymbolAliasMapEntry(Name, Flags); |
| 152 | } |
| 153 | }); |
Lang Hames | 68c9b8d | 2018-06-18 18:01:43 +0000 | [diff] [blame] | 154 | |
Lang Hames | 9844029 | 2018-09-29 23:49:57 +0000 | [diff] [blame] | 155 | // Create a partitioning materialization unit and lodge it with the |
| 156 | // implementation dylib. |
| 157 | if (auto Err = PDR.getImplDylib().define( |
| 158 | llvm::make_unique<PartitioningIRMaterializationUnit>( |
Lang Hames | 8b94274 | 2018-10-16 20:13:06 +0000 | [diff] [blame] | 159 | ES, std::move(TSM), R.getVModuleKey(), *this))) { |
Lang Hames | 68c9b8d | 2018-06-18 18:01:43 +0000 | [diff] [blame] | 160 | ES.reportError(std::move(Err)); |
| 161 | R.failMaterialization(); |
| 162 | return; |
| 163 | } |
| 164 | |
Lang Hames | 23cb2e7 | 2018-10-23 23:01:39 +0000 | [diff] [blame] | 165 | R.replace(reexports(PDR.getImplDylib(), std::move(NonCallables), true)); |
Lang Hames | 9844029 | 2018-09-29 23:49:57 +0000 | [diff] [blame] | 166 | R.replace(lazyReexports(LCTMgr, PDR.getISManager(), PDR.getImplDylib(), |
Praveen Velliengiri | f5c40cb | 2019-08-03 14:42:13 +0000 | [diff] [blame^] | 167 | std::move(Callables), AliaseeImpls)); |
Lang Hames | 68c9b8d | 2018-06-18 18:01:43 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Lang Hames | 079df9a | 2018-10-15 22:56:10 +0000 | [diff] [blame] | 170 | CompileOnDemandLayer::PerDylibResources & |
| 171 | CompileOnDemandLayer::getPerDylibResources(JITDylib &TargetD) { |
Lang Hames | d804867 | 2018-09-26 05:08:29 +0000 | [diff] [blame] | 172 | auto I = DylibResources.find(&TargetD); |
| 173 | if (I == DylibResources.end()) { |
Lang Hames | 23cb2e7 | 2018-10-23 23:01:39 +0000 | [diff] [blame] | 174 | auto &ImplD = getExecutionSession().createJITDylib( |
| 175 | TargetD.getName() + ".impl", false); |
| 176 | TargetD.withSearchOrderDo([&](const JITDylibSearchList &TargetSearchOrder) { |
| 177 | auto NewSearchOrder = TargetSearchOrder; |
| 178 | assert(!NewSearchOrder.empty() && |
| 179 | NewSearchOrder.front().first == &TargetD && |
| 180 | NewSearchOrder.front().second == true && |
| 181 | "TargetD must be at the front of its own search order and match " |
| 182 | "non-exported symbol"); |
| 183 | NewSearchOrder.insert(std::next(NewSearchOrder.begin()), {&ImplD, true}); |
| 184 | ImplD.setSearchOrder(std::move(NewSearchOrder), false); |
Lang Hames | d804867 | 2018-09-26 05:08:29 +0000 | [diff] [blame] | 185 | }); |
| 186 | PerDylibResources PDR(ImplD, BuildIndirectStubsManager()); |
| 187 | I = DylibResources.insert(std::make_pair(&TargetD, std::move(PDR))).first; |
| 188 | } |
| 189 | |
| 190 | return I->second; |
Lang Hames | 68c9b8d | 2018-06-18 18:01:43 +0000 | [diff] [blame] | 191 | } |
| 192 | |
Lang Hames | 079df9a | 2018-10-15 22:56:10 +0000 | [diff] [blame] | 193 | void CompileOnDemandLayer::cleanUpModule(Module &M) { |
Lang Hames | 9844029 | 2018-09-29 23:49:57 +0000 | [diff] [blame] | 194 | for (auto &F : M.functions()) { |
| 195 | if (F.isDeclaration()) |
| 196 | continue; |
| 197 | |
| 198 | if (F.hasAvailableExternallyLinkage()) { |
| 199 | F.deleteBody(); |
| 200 | F.setPersonalityFn(nullptr); |
| 201 | continue; |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | |
Lang Hames | 079df9a | 2018-10-15 22:56:10 +0000 | [diff] [blame] | 206 | void CompileOnDemandLayer::expandPartition(GlobalValueSet &Partition) { |
Lang Hames | 9844029 | 2018-09-29 23:49:57 +0000 | [diff] [blame] | 207 | // Expands the partition to ensure the following rules hold: |
| 208 | // (1) If any alias is in the partition, its aliasee is also in the partition. |
| 209 | // (2) If any aliasee is in the partition, its aliases are also in the |
| 210 | // partiton. |
| 211 | // (3) If any global variable is in the partition then all global variables |
| 212 | // are in the partition. |
| 213 | assert(!Partition.empty() && "Unexpected empty partition"); |
| 214 | |
| 215 | const Module &M = *(*Partition.begin())->getParent(); |
| 216 | bool ContainsGlobalVariables = false; |
| 217 | std::vector<const GlobalValue *> GVsToAdd; |
| 218 | |
| 219 | for (auto *GV : Partition) |
| 220 | if (isa<GlobalAlias>(GV)) |
| 221 | GVsToAdd.push_back( |
| 222 | cast<GlobalValue>(cast<GlobalAlias>(GV)->getAliasee())); |
| 223 | else if (isa<GlobalVariable>(GV)) |
| 224 | ContainsGlobalVariables = true; |
| 225 | |
| 226 | for (auto &A : M.aliases()) |
| 227 | if (Partition.count(cast<GlobalValue>(A.getAliasee()))) |
| 228 | GVsToAdd.push_back(&A); |
| 229 | |
| 230 | if (ContainsGlobalVariables) |
| 231 | for (auto &G : M.globals()) |
| 232 | GVsToAdd.push_back(&G); |
| 233 | |
| 234 | for (auto *GV : GVsToAdd) |
| 235 | Partition.insert(GV); |
| 236 | } |
| 237 | |
Lang Hames | 079df9a | 2018-10-15 22:56:10 +0000 | [diff] [blame] | 238 | void CompileOnDemandLayer::emitPartition( |
Lang Hames | 9844029 | 2018-09-29 23:49:57 +0000 | [diff] [blame] | 239 | MaterializationResponsibility R, ThreadSafeModule TSM, |
| 240 | IRMaterializationUnit::SymbolNameToDefinitionMap Defs) { |
| 241 | |
| 242 | // FIXME: Need a 'notify lazy-extracting/emitting' callback to tie the |
| 243 | // extracted module key, extracted module, and source module key |
| 244 | // together. This could be used, for example, to provide a specific |
| 245 | // memory manager instance to the linking layer. |
| 246 | |
| 247 | auto &ES = getExecutionSession(); |
Lang Hames | 9844029 | 2018-09-29 23:49:57 +0000 | [diff] [blame] | 248 | GlobalValueSet RequestedGVs; |
| 249 | for (auto &Name : R.getRequestedSymbols()) { |
| 250 | assert(Defs.count(Name) && "No definition for symbol"); |
| 251 | RequestedGVs.insert(Defs[Name]); |
| 252 | } |
| 253 | |
Lang Hames | 809e9d1 | 2019-08-02 15:21:37 +0000 | [diff] [blame] | 254 | /// Perform partitioning with the context lock held, since the partition |
| 255 | /// function is allowed to access the globals to compute the partition. |
| 256 | auto GVsToExtract = |
| 257 | TSM.withModuleDo([&](Module &M) { return Partition(RequestedGVs); }); |
Lang Hames | 9844029 | 2018-09-29 23:49:57 +0000 | [diff] [blame] | 258 | |
| 259 | // Take a 'None' partition to mean the whole module (as opposed to an empty |
| 260 | // partition, which means "materialize nothing"). Emit the whole module |
| 261 | // unmodified to the base layer. |
| 262 | if (GVsToExtract == None) { |
| 263 | Defs.clear(); |
Lang Hames | 8b94274 | 2018-10-16 20:13:06 +0000 | [diff] [blame] | 264 | BaseLayer.emit(std::move(R), std::move(TSM)); |
Lang Hames | 9844029 | 2018-09-29 23:49:57 +0000 | [diff] [blame] | 265 | return; |
| 266 | } |
| 267 | |
| 268 | // If the partition is empty, return the whole module to the symbol table. |
| 269 | if (GVsToExtract->empty()) { |
| 270 | R.replace(llvm::make_unique<PartitioningIRMaterializationUnit>( |
| 271 | std::move(TSM), R.getSymbols(), std::move(Defs), *this)); |
| 272 | return; |
| 273 | } |
| 274 | |
Lang Hames | bf6603e | 2018-10-09 20:44:32 +0000 | [diff] [blame] | 275 | // Ok -- we actually need to partition the symbols. Promote the symbol |
Lang Hames | 809e9d1 | 2019-08-02 15:21:37 +0000 | [diff] [blame] | 276 | // linkages/names, expand the partition to include any required symbols |
| 277 | // (i.e. symbols that can't be separated from our partition), and |
| 278 | // then extract the partition. |
| 279 | // |
| 280 | // FIXME: We apply this promotion once per partitioning. It's safe, but |
| 281 | // overkill. |
| 282 | |
| 283 | auto ExtractedTSM = |
| 284 | TSM.withModuleDo([&](Module &M) -> Expected<ThreadSafeModule> { |
| 285 | auto PromotedGlobals = PromoteSymbols(M); |
| 286 | if (!PromotedGlobals.empty()) { |
| 287 | MangleAndInterner Mangle(ES, M.getDataLayout()); |
| 288 | SymbolFlagsMap SymbolFlags; |
| 289 | for (auto &GV : PromotedGlobals) |
| 290 | SymbolFlags[Mangle(GV->getName())] = |
| 291 | JITSymbolFlags::fromGlobalValue(*GV); |
| 292 | if (auto Err = R.defineMaterializing(SymbolFlags)) |
| 293 | return std::move(Err); |
| 294 | } |
| 295 | |
| 296 | expandPartition(*GVsToExtract); |
| 297 | |
| 298 | // Extract the requested partiton (plus any necessary aliases) and |
| 299 | // put the rest back into the impl dylib. |
| 300 | auto ShouldExtract = [&](const GlobalValue &GV) -> bool { |
| 301 | return GVsToExtract->count(&GV); |
| 302 | }; |
| 303 | |
| 304 | return extractSubModule(TSM, ".submodule", ShouldExtract); |
| 305 | }); |
| 306 | |
| 307 | if (!ExtractedTSM) { |
| 308 | ES.reportError(ExtractedTSM.takeError()); |
| 309 | R.failMaterialization(); |
| 310 | return; |
Lang Hames | bf6603e | 2018-10-09 20:44:32 +0000 | [diff] [blame] | 311 | } |
| 312 | |
Lang Hames | 9844029 | 2018-09-29 23:49:57 +0000 | [diff] [blame] | 313 | R.replace(llvm::make_unique<PartitioningIRMaterializationUnit>( |
Lang Hames | 8b94274 | 2018-10-16 20:13:06 +0000 | [diff] [blame] | 314 | ES, std::move(TSM), R.getVModuleKey(), *this)); |
Lang Hames | 809e9d1 | 2019-08-02 15:21:37 +0000 | [diff] [blame] | 315 | BaseLayer.emit(std::move(R), std::move(*ExtractedTSM)); |
Lang Hames | 68c9b8d | 2018-06-18 18:01:43 +0000 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | } // end namespace orc |
| 319 | } // end namespace llvm |