diff options
| author | Lang Hames <lhames@gmail.com> | 2018-06-26 21:35:48 +0000 |
|---|---|---|
| committer | Lang Hames <lhames@gmail.com> | 2018-06-26 21:35:48 +0000 |
| commit | 6a94134b1167d1245058ce65b3c8c33956d37ec3 (patch) | |
| tree | 9bc0185702953f139e731e6018d0861c3604d9a5 /llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp | |
| parent | 777477705a7b00450d17504d08fa9ec7d2ba4ebb (diff) | |
| download | bcm5719-llvm-6a94134b1167d1245058ce65b3c8c33956d37ec3.tar.gz bcm5719-llvm-6a94134b1167d1245058ce65b3c8c33956d37ec3.zip | |
[ORC] Add LLJIT and LLLazyJIT, and replace OrcLazyJIT in LLI with LLLazyJIT.
LLJIT is a prefabricated ORC based JIT class that is meant to be the go-to
replacement for MCJIT. Unlike OrcMCJITReplacement (which will continue to be
supported) it is not API or bug-for-bug compatible, but targets the same
use cases: Simple, non-lazy compilation and execution of LLVM IR.
LLLazyJIT extends LLJIT with support for function-at-a-time lazy compilation,
similar to what was provided by LLVM's original (now long deprecated) JIT APIs.
This commit also contains some simple utility classes (CtorDtorRunner2,
LocalCXXRuntimeOverrides2, JITTargetMachineBuilder) to support LLJIT and
LLLazyJIT.
Both of these classes are works in progress. Feedback from JIT clients is very
welcome!
llvm-svn: 335670
Diffstat (limited to 'llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp')
| -rw-r--r-- | llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp | 56 |
1 files changed, 48 insertions, 8 deletions
diff --git a/llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp b/llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp index 584f990976a..27a4ad68f59 100644 --- a/llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp +++ b/llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp @@ -35,12 +35,42 @@ createLambdaValueMaterializer(MaterializerFtor M) { } } // namespace +static void extractAliases(MaterializationResponsibility &R, Module &M, + MangleAndInterner &Mangle) { + SymbolAliasMap Aliases; + + std::vector<GlobalAlias *> ModAliases; + for (auto &A : M.aliases()) + ModAliases.push_back(&A); + + for (auto *A : ModAliases) { + Constant *Aliasee = A->getAliasee(); + assert(A->hasName() && "Anonymous alias?"); + assert(Aliasee->hasName() && "Anonymous aliasee"); + std::string AliasName = A->getName(); + + Aliases[Mangle(AliasName)] = SymbolAliasMapEntry( + {Mangle(Aliasee->getName()), JITSymbolFlags::fromGlobalValue(*A)}); + + if (isa<Function>(Aliasee)) { + auto *F = cloneFunctionDecl(M, *cast<Function>(Aliasee)); + A->replaceAllUsesWith(F); + A->eraseFromParent(); + F->setName(AliasName); + } else if (isa<GlobalValue>(Aliasee)) { + auto *G = cloneGlobalVariableDecl(M, *cast<GlobalVariable>(Aliasee)); + A->replaceAllUsesWith(G); + A->eraseFromParent(); + G->setName(AliasName); + } + } + + R.delegate(symbolAliases(std::move(Aliases))); +} + static std::unique_ptr<Module> extractGlobals(Module &M) { // FIXME: Add alias support. - if (M.global_empty() && M.alias_empty() && !M.getModuleFlagsMetadata()) - return nullptr; - auto GlobalsModule = llvm::make_unique<Module>( (M.getName() + ".globals").str(), M.getContext()); GlobalsModule->setDataLayout(M.getDataLayout()); @@ -161,7 +191,6 @@ CompileOnDemandLayer2::CompileOnDemandLayer2( Error CompileOnDemandLayer2::add(VSO &V, VModuleKey K, std::unique_ptr<Module> M) { - makeAllSymbolsExternallyAccessible(*M); return IRLayer::add(V, K, std::move(M)); } @@ -174,10 +203,12 @@ void CompileOnDemandLayer2::emit(MaterializationResponsibility R, VModuleKey K, if (GV.hasWeakLinkage()) GV.setLinkage(GlobalValue::ExternalLinkage); - auto GlobalsModule = extractGlobals(*M); - MangleAndInterner Mangle(ES, M->getDataLayout()); + extractAliases(R, *M, Mangle); + + auto GlobalsModule = extractGlobals(*M); + // Delete the bodies of any available externally functions, rename the // rest, and build the compile callbacks. std::map<SymbolStringPtr, std::pair<JITTargetAddress, JITSymbolFlags>> @@ -194,8 +225,12 @@ void CompileOnDemandLayer2::emit(MaterializationResponsibility R, VModuleKey K, } assert(F.hasName() && "Function should have a name"); - auto StubName = Mangle(F.getName()); + std::string StubUnmangledName = F.getName(); F.setName(F.getName() + "$body"); + auto StubDecl = cloneFunctionDecl(*M, F); + StubDecl->setName(StubUnmangledName); + F.replaceAllUsesWith(StubDecl); + auto StubName = Mangle(StubUnmangledName); auto BodyName = Mangle(F.getName()); if (auto CallbackAddr = CCMgr.getCompileCallback( [BodyName, &TargetVSO, &ES]() -> JITTargetAddress { @@ -223,14 +258,19 @@ void CompileOnDemandLayer2::emit(MaterializationResponsibility R, VModuleKey K, StubInits[*KV.first] = KV.second; // Build the function-body-extracting materialization unit. + auto SR = GetSymbolResolver(K); if (auto Err = R.getTargetVSO().define( llvm::make_unique<ExtractingIRMaterializationUnit>( - ES, *this, std::move(M), GetSymbolResolver(K)))) { + ES, *this, std::move(M), SR))) { ES.reportError(std::move(Err)); R.failMaterialization(); return; } + // Replace the fallback symbol resolver: We will re-use M's VModuleKey for + // the GlobalsModule. + SetSymbolResolver(K, SR); + // Build the stubs. // FIXME: Remove function bodies materialization unit if stub creation fails. auto &StubsMgr = getStubsManager(TargetVSO); |

