<div dir="ltr"><div>Hi Dave,</div><div><br></div><div>emitAndFinalize exists to control emission when the symbols contained in the module are irrelevant (e.g. the finalization is being forced for performance reasons, not because a symbol is currently required), or invisible to findSymbol (e.g. the desired symbol is a common symbol or contained in inline assembly).</div><div><br></div><div>If the user wants a symbol they should use findSymbol/findSymbolIn.</div><div><br></div><div>Cheers,</div><div>Lang.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 17, 2015 at 10:58 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">Should emitAndFinalize return the address or SymbolRef? It'd often be used in resolvers followed immediately by a query for the address, would it not?<div><div class="h5"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 16, 2015 at 2:36 PM, Lang Hames <span dir="ltr"><<a href="mailto:lhames@gmail.com" target="_blank">lhames@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: lhames<br>
Date: Mon Feb 16 16:36:25 2015<br>
New Revision: 229451<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=229451&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=229451&view=rev</a><br>
Log:<br>
[Orc] Add an emitAndFinalize method to the ObjectLinkingLayer, IRCompileLayer<br>
and LazyEmittingLayer of Orc.<br>
<br>
This method allows you to immediately emit and finalize a module. It is required<br>
by an upcoming refactor of the indirection utils and the compile-on-demand<br>
layer.<br>
<br>
I've filed <a href="http://llvm.org/PR22608" target="_blank">http://llvm.org/PR22608</a> to write unit tests for this and other Orc<br>
APIs.<br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h<br>
    llvm/trunk/include/llvm/ExecutionEngine/Orc/LazyEmittingLayer.h<br>
    llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h<br>
<br>
Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h?rev=229451&r1=229450&r2=229451&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h?rev=229451&r1=229450&r2=229451&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h (original)<br>
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h Mon Feb 16 16:36:25 2015<br>
@@ -111,6 +111,13 @@ public:<br>
     return BaseLayer.findSymbolIn(H, Name, ExportedSymbolsOnly);<br>
   }<br>
<br>
+  /// @brief Immediately emit and finalize the moduleOB set represented by the<br>
+  ///        given handle.<br>
+  /// @param H Handle for module set to emit/finalize.<br>
+  void emitAndFinalize(ModuleSetHandleT H) {<br>
+    BaseLayer.emitAndFinalize(H);<br>
+  }<br>
+<br>
 private:<br>
   object::OwningBinary<object::ObjectFile><br>
   tryToLoadFromObjectCache(const Module &M) {<br>
<br>
Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/LazyEmittingLayer.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/LazyEmittingLayer.h?rev=229451&r1=229450&r2=229451&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/LazyEmittingLayer.h?rev=229451&r1=229450&r2=229451&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/LazyEmittingLayer.h (original)<br>
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/LazyEmittingLayer.h Mon Feb 16 16:36:25 2015<br>
@@ -53,7 +53,7 @@ private:<br>
                   return 0;<br>
                 else if (this->EmitState == NotEmitted) {<br>
                   this->EmitState = Emitting;<br>
-                  Handle = this->emit(B);<br>
+                  Handle = this->emitToBaseLayer(B);<br>
                   this->EmitState = Emitted;<br>
                 }<br>
                 return B.findSymbolIn(Handle, PName, ExportedSymbolsOnly)<br>
@@ -78,6 +78,17 @@ private:<br>
         BaseLayer.removeModuleSet(Handle);<br>
     }<br>
<br>
+    void emitAndFinalize(BaseLayerT &BaseLayer) {<br>
+      assert(EmitState != Emitting &&<br>
+             "Cannot emitAndFinalize while already emitting");<br>
+      if (EmitState == NotEmitted) {<br>
+        EmitState = Emitting;<br>
+        Handle = emitToBaseLayer(BaseLayer);<br>
+        EmitState = Emitted;<br>
+      }<br>
+      BaseLayer.emitAndFinalize(Handle);<br>
+    }<br>
+<br>
     template <typename ModuleSetT><br>
     static std::unique_ptr<EmissionDeferredSet><br>
     create(BaseLayerT &B, ModuleSetT Ms,<br>
@@ -85,7 +96,7 @@ private:<br>
<br>
   protected:<br>
     virtual bool provides(StringRef Name, bool ExportedSymbolsOnly) const = 0;<br>
-    virtual BaseLayerHandleT emit(BaseLayerT &BaseLayer) = 0;<br>
+    virtual BaseLayerHandleT emitToBaseLayer(BaseLayerT &BaseLayer) = 0;<br>
<br>
   private:<br>
     enum { NotEmitted, Emitting, Emitted } EmitState;<br>
@@ -100,7 +111,8 @@ private:<br>
         : Ms(std::move(Ms)), MM(std::move(MM)) {}<br>
<br>
   protected:<br>
-    BaseLayerHandleT emit(BaseLayerT &BaseLayer) override {<br>
+<br>
+    BaseLayerHandleT emitToBaseLayer(BaseLayerT &BaseLayer) override {<br>
       // We don't need the mangled names set any more: Once we've emitted this<br>
       // to the base layer we'll just look for symbols there.<br>
       MangledNames.reset();<br>
@@ -243,6 +255,14 @@ public:<br>
                          bool ExportedSymbolsOnly) {<br>
     return (*H)->find(Name, ExportedSymbolsOnly, BaseLayer);<br>
   }<br>
+<br>
+  /// @brief Immediately emit and finalize the moduleOB set represented by the<br>
+  ///        given handle.<br>
+  /// @param H Handle for module set to emit/finalize.<br>
+  void emitAndFinalize(ModuleSetHandleT H) {<br>
+    (*H)->emitAndFinalize(BaseLayer);<br>
+  }<br>
+<br>
 };<br>
<br>
 template <typename BaseLayerT><br>
<br>
Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h?rev=229451&r1=229450&r2=229451&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h?rev=229451&r1=229450&r2=229451&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h (original)<br>
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h Mon Feb 16 16:36:25 2015<br>
@@ -178,12 +178,6 @@ public:<br>
     return Handle;<br>
   }<br>
<br>
-  /// @brief Map section addresses for the objects associated with the handle H.<br>
-  void mapSectionAddress(ObjSetHandleT H, const void *LocalAddress,<br>
-                         TargetAddress TargetAddr) {<br>
-    H->mapSectionAddress(LocalAddress, TargetAddr);<br>
-  }<br>
-<br>
   /// @brief Remove the set of objects associated with handle H.<br>
   ///<br>
   ///   All memory allocated for the objects will be freed, and the sections and<br>
@@ -233,6 +227,21 @@ public:<br>
     return nullptr;<br>
   }<br>
<br>
+  /// @brief Map section addresses for the objects associated with the handle H.<br>
+  void mapSectionAddress(ObjSetHandleT H, const void *LocalAddress,<br>
+                         TargetAddress TargetAddr) {<br>
+    H->mapSectionAddress(LocalAddress, TargetAddr);<br>
+  }<br>
+<br>
+  /// @brief Immediately emit and finalize the object set represented by the<br>
+  ///        given handle.<br>
+  /// @param H Handle for object set to emit/finalize.<br>
+  void emitAndFinalize(ObjSetHandleT H) {<br>
+    H->Finalize();<br>
+    if (NotifyFinalized)<br>
+      NotifyFinalized(H);<br>
+  }<br>
+<br>
 private:<br>
   LinkedObjectSetListT LinkedObjSetList;<br>
   NotifyLoadedFtor NotifyLoaded;<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div></div></div>
</blockquote></div><br></div>