<div dir="ltr">Hi Dave,<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span style="font-size:12.800000190734863px">Why is the C binding the best path to testing this? That seems strange/surprising to me. (would expect it'd be testable via the C++ API in a more narrow way sooner/without as much other infrastructure)</span></blockquote><div><br></div><div>Actually we could add a test to the CompileOnDemandLayer tests that "updatePointer" returns true for a symbol that has been added, and false otherwise.</div><div><br></div><div>To actually test the behavior though we need an execution test. Since execution unit tests have a higher maintenance burden (can only be run on certain platforms, require a fully working stack) we only maintain one: the C Bindings Stack unit test.</div><div><br></div><div>- Lang.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 1, 2016 at 9:28 AM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><br><div class="gmail_quote"><span class=""><div dir="ltr">On Fri, Jul 29, 2016 at 6:05 PM Lang Hames via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: lhames<br>
Date: Fri Jul 29 19:57:54 2016<br>
New Revision: 277257<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=277257&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=277257&view=rev</a><br>
Log:<br>
[Orc] Add support for updating stub targets to CompileOnDemandLayer.<br>
<br>
This makes it possible to implement re-optimization on top of the<br>
CompileOnDemandLayer.<br>
<br>
Test case to come in a future patch: This will need an execution test, and<br>
execution tests require a full working stack. The best option is to plumb this<br>
API up to the C Bindings stack and add a C bindings test for this.<br></blockquote><div><br></div></span><div>Why is the C binding the best path to testing this? That seems strange/surprising to me. (would expect it'd be testable via the C++ API in a more narrow way sooner/without as much other infrastructure)</div><div><div class="h5"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Patch by Sean Ogden. Thanks Sean!<br>
<br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h<br>
    llvm/trunk/include/llvm/ExecutionEngine/Orc/LogicalDylib.h<br>
<br>
Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h?rev=277257&r1=277256&r2=277257&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h?rev=277257&r1=277256&r2=277257&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h (original)<br>
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h Fri Jul 29 19:57:54 2016<br>
@@ -236,6 +236,32 @@ public:<br>
     return H->findSymbol(Name, ExportedSymbolsOnly);<br>
   }<br>
<br>
+  /// @brief Update the stub for the given function to point at FnBodyAddr.<br>
+  /// This can be used to support re-optimization.<br>
+  /// @return true if the function exists and the stub is updated, false<br>
+  ///         otherwise.<br>
+  //<br>
+  // FIXME: We should track and free associated resources (unused compile<br>
+  //        callbacks, uncompiled IR, and no-longer-needed/reachable function<br>
+  //        implementations).<br>
+  // FIXME: Return Error once the JIT APIs are Errorized.<br>
+  bool updatePointer(std::string FuncName, TargetAddress FnBodyAddr) {<br>
+    //Find out which logical dylib contains our symbol<br>
+    auto LDI = LogicalDylibs.begin();<br>
+    for (auto LDE = LogicalDylibs.end(); LDI != LDE; ++LDI) {<br>
+      if (auto LMResources = LDI->getLogicalModuleResourcesForSymbol(FuncName, false)) {<br>
+        Module &SrcM = LMResources->SourceModule->getResource();<br>
+        std::string CalledFnName = mangle(FuncName, SrcM.getDataLayout());<br>
+        if (auto EC = LMResources->StubsMgr->updatePointer(CalledFnName, FnBodyAddr)) {<br>
+          return false;<br>
+        }<br>
+        else<br>
+          return true;<br>
+      }<br>
+    }<br>
+    return false;<br>
+  }<br>
+<br>
 private:<br>
<br>
   template <typename ModulePtrT><br>
<br>
Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/LogicalDylib.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/LogicalDylib.h?rev=277257&r1=277256&r2=277257&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/LogicalDylib.h?rev=277257&r1=277256&r2=277257&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/LogicalDylib.h (original)<br>
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/LogicalDylib.h Fri Jul 29 19:57:54 2016<br>
@@ -123,6 +123,16 @@ public:<br>
<br>
   LogicalDylibResources& getDylibResources() { return DylibResources; }<br>
<br>
+  LogicalModuleResources*<br>
+  getLogicalModuleResourcesForSymbol(const std::string &Name,<br>
+                                     bool ExportedSymbolsOnly) {<br>
+    for (auto LMI = LogicalModules.begin(), LME = LogicalModules.end();<br>
+         LMI != LME; ++LMI)<br>
+      if (auto Sym = LMI->Resources.findSymbol(Name, ExportedSymbolsOnly))<br>
+        return &LMI->Resources;<br>
+    return nullptr;<br>
+  }<br>
+<br>
 protected:<br>
   BaseLayerT BaseLayer;<br>
   LogicalModuleList LogicalModules;<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div></div></div>
</blockquote></div><br></div>