From c31d594228f9bcd555f2e7439f33023cba192c15 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Sat, 30 Jul 2016 00:57:54 +0000 Subject: [PATCH] [Orc] Add support for updating stub targets to CompileOnDemandLayer. This makes it possible to implement re-optimization on top of the CompileOnDemandLayer. Test case to come in a future patch: This will need an execution test, and execution tests require a full working stack. The best option is to plumb this API up to the C Bindings stack and add a C bindings test for this. Patch by Sean Ogden. Thanks Sean! llvm-svn: 277257 --- .../ExecutionEngine/Orc/CompileOnDemandLayer.h | 26 ++++++++++++++++++++++ .../llvm/ExecutionEngine/Orc/LogicalDylib.h | 10 +++++++++ 2 files changed, 36 insertions(+) diff --git a/llvm/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h index ef88dd0..9a6a9de 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h @@ -236,6 +236,32 @@ public: return H->findSymbol(Name, ExportedSymbolsOnly); } + /// @brief Update the stub for the given function to point at FnBodyAddr. + /// This can be used to support re-optimization. + /// @return true if the function exists and the stub is updated, false + /// otherwise. + // + // FIXME: We should track and free associated resources (unused compile + // callbacks, uncompiled IR, and no-longer-needed/reachable function + // implementations). + // FIXME: Return Error once the JIT APIs are Errorized. + bool updatePointer(std::string FuncName, TargetAddress FnBodyAddr) { + //Find out which logical dylib contains our symbol + auto LDI = LogicalDylibs.begin(); + for (auto LDE = LogicalDylibs.end(); LDI != LDE; ++LDI) { + if (auto LMResources = LDI->getLogicalModuleResourcesForSymbol(FuncName, false)) { + Module &SrcM = LMResources->SourceModule->getResource(); + std::string CalledFnName = mangle(FuncName, SrcM.getDataLayout()); + if (auto EC = LMResources->StubsMgr->updatePointer(CalledFnName, FnBodyAddr)) { + return false; + } + else + return true; + } + } + return false; + } + private: template diff --git a/llvm/include/llvm/ExecutionEngine/Orc/LogicalDylib.h b/llvm/include/llvm/ExecutionEngine/Orc/LogicalDylib.h index 883fa9e..914b112 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/LogicalDylib.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/LogicalDylib.h @@ -123,6 +123,16 @@ public: LogicalDylibResources& getDylibResources() { return DylibResources; } + LogicalModuleResources* + getLogicalModuleResourcesForSymbol(const std::string &Name, + bool ExportedSymbolsOnly) { + for (auto LMI = LogicalModules.begin(), LME = LogicalModules.end(); + LMI != LME; ++LMI) + if (auto Sym = LMI->Resources.findSymbol(Name, ExportedSymbolsOnly)) + return &LMI->Resources; + return nullptr; + } + protected: BaseLayerT BaseLayer; LogicalModuleList LogicalModules; -- 2.7.4