<div dir="ltr">Re-applied in r<span style="font-size:12.800000190734863px">306182.</span></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 23, 2017 at 4:07 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"><div dir="ltr">Ugh. Too late. ><</div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 23, 2017 at 4:05 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"><div dir="ltr">I've got in a fix in the works. Should be in shortly.<span class="m_-2149766475176581218HOEnZb"><font color="#888888"><div><br></div><div>- Lang.</div><div><br></div></font></span></div><div class="m_-2149766475176581218HOEnZb"><div class="m_-2149766475176581218h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 23, 2017 at 3:50 PM, Rafael Avila de Espindola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This is causing test failures on linux. Reverting.<br>
<br>
Cheers,<br>
Rafael<br>
<div class="m_-2149766475176581218m_5844292046495427497HOEnZb"><div class="m_-2149766475176581218m_5844292046495427497h5"><br>
Lang Hames via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> writes:<br>
<br>
> Author: lhames<br>
> Date: Fri Jun 23 16:45:29 2017<br>
> New Revision: 306166<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=306166&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject?rev=306166&view=rev</a><br>
> Log:<br>
> [ORC] Move ORC IR layer interface from addModuleSet to addModule and fix the<br>
> module type as std::shared_ptr<Module>.<br>
><br>
><br>
> Modified:<br>
>     llvm/trunk/examples/Kaleidosc<wbr>ope/BuildingAJIT/Chapter1/Kale<wbr>idoscopeJIT.h<br>
>     llvm/trunk/examples/Kaleidosc<wbr>ope/BuildingAJIT/Chapter2/Kale<wbr>idoscopeJIT.h<br>
>     llvm/trunk/examples/Kaleidosc<wbr>ope/BuildingAJIT/Chapter3/Kale<wbr>idoscopeJIT.h<br>
>     llvm/trunk/examples/Kaleidosc<wbr>ope/BuildingAJIT/Chapter4/Kale<wbr>idoscopeJIT.h<br>
>     llvm/trunk/examples/Kaleidosc<wbr>ope/BuildingAJIT/Chapter5/Kale<wbr>idoscopeJIT.h<br>
>     llvm/trunk/examples/Kaleidosc<wbr>ope/include/KaleidoscopeJIT.h<br>
>     llvm/trunk/include/llvm-c/Orc<wbr>Bindings.h<br>
>     llvm/trunk/include/llvm/Execu<wbr>tionEngine/Orc/CompileOnDemand<wbr>Layer.h<br>
>     llvm/trunk/include/llvm/Execu<wbr>tionEngine/Orc/ExecutionUtils.<wbr>h<br>
>     llvm/trunk/include/llvm/Execu<wbr>tionEngine/Orc/IRCompileLayer.<wbr>h<br>
>     llvm/trunk/include/llvm/Execu<wbr>tionEngine/Orc/IRTransformLaye<wbr>r.h<br>
>     llvm/trunk/include/llvm/Execu<wbr>tionEngine/Orc/LazyEmittingLay<wbr>er.h<br>
>     llvm/trunk/lib/ExecutionEngin<wbr>e/Orc/OrcCBindings.cpp<br>
>     llvm/trunk/lib/ExecutionEngin<wbr>e/Orc/OrcCBindingsStack.h<br>
>     llvm/trunk/lib/ExecutionEngin<wbr>e/Orc/OrcMCJITReplacement.h<br>
>     llvm/trunk/tools/lli/OrcLazyJ<wbr>IT.cpp<br>
>     llvm/trunk/tools/lli/OrcLazyJ<wbr>IT.h<br>
>     llvm/trunk/unittests/Executio<wbr>nEngine/Orc/LazyEmittingLayerT<wbr>est.cpp<br>
>     llvm/trunk/unittests/Executio<wbr>nEngine/Orc/ObjectTransformLay<wbr>erTest.cpp<br>
>     llvm/trunk/unittests/Executio<wbr>nEngine/Orc/OrcCAPITest.cpp<br>
>     llvm/trunk/unittests/Executio<wbr>nEngine/Orc/OrcTestCommon.h<br>
><br>
> Modified: llvm/trunk/examples/Kaleidosco<wbr>pe/BuildingAJIT/Chapter1/Kalei<wbr>doscopeJIT.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h?rev=306166&r1=306165&r2=306166&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/examples/Kale<wbr>idoscope/BuildingAJIT/Chapter1<wbr>/KaleidoscopeJIT.h?rev=306166&<wbr>r1=306165&r2=306166&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/examples/Kaleidosco<wbr>pe/BuildingAJIT/Chapter1/Kalei<wbr>doscopeJIT.h (original)<br>
> +++ llvm/trunk/examples/Kaleidosco<wbr>pe/BuildingAJIT/Chapter1/Kalei<wbr>doscopeJIT.h Fri Jun 23 16:45:29 2017<br>
> @@ -44,7 +44,7 @@ private:<br>
>    IRCompileLayer<decltype(Object<wbr>Layer), SimpleCompiler> CompileLayer;<br>
><br>
>  public:<br>
> -  using ModuleHandle = decltype(CompileLayer)::Module<wbr>SetHandleT;<br>
> +  using ModuleHandle = decltype(CompileLayer)::Module<wbr>HandleT;<br>
><br>
>    KaleidoscopeJIT()<br>
>        : TM(EngineBuilder().selectTarge<wbr>t()), DL(TM->createDataLayout()),<br>
> @@ -72,15 +72,11 @@ public:<br>
>            return JITSymbol(nullptr);<br>
>          });<br>
><br>
> -    // Build a singleton module set to hold our module.<br>
> -    std::vector<std::unique_ptr<Mo<wbr>dule>> Ms;<br>
> -    Ms.push_back(std::move(M));<br>
> -<br>
>      // Add the set to the JIT with the resolver we created above and a newly<br>
>      // created SectionMemoryManager.<br>
> -    return CompileLayer.addModuleSet(std:<wbr>:move(Ms),<br>
> -                                     make_unique<SectionMemoryMana<wbr>ger>(),<br>
> -                                     std::move(Resolver));<br>
> +    return CompileLayer.addModule(std::mo<wbr>ve(M),<br>
> +                                  make_unique<SectionMemoryManag<wbr>er>(),<br>
> +                                  std::move(Resolver));<br>
>    }<br>
><br>
>    JITSymbol findSymbol(const std::string Name) {<br>
> @@ -91,7 +87,7 @@ public:<br>
>    }<br>
><br>
>    void removeModule(ModuleHandle H) {<br>
> -    CompileLayer.removeModuleSet(H<wbr>);<br>
> +    CompileLayer.removeModule(H);<br>
>    }<br>
>  };<br>
><br>
><br>
> Modified: llvm/trunk/examples/Kaleidosco<wbr>pe/BuildingAJIT/Chapter2/Kalei<wbr>doscopeJIT.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h?rev=306166&r1=306165&r2=306166&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/examples/Kale<wbr>idoscope/BuildingAJIT/Chapter2<wbr>/KaleidoscopeJIT.h?rev=306166&<wbr>r1=306165&r2=306166&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/examples/Kaleidosco<wbr>pe/BuildingAJIT/Chapter2/Kalei<wbr>doscopeJIT.h (original)<br>
> +++ llvm/trunk/examples/Kaleidosco<wbr>pe/BuildingAJIT/Chapter2/Kalei<wbr>doscopeJIT.h Fri Jun 23 16:45:29 2017<br>
> @@ -48,18 +48,18 @@ private:<br>
>    IRCompileLayer<decltype(Object<wbr>Layer), SimpleCompiler> CompileLayer;<br>
><br>
>    using OptimizeFunction =<br>
> -      std::function<std::unique_ptr<<wbr>Module>(std::unique_ptr<Module<wbr>>)>;<br>
> +      std::function<std::shared_ptr<<wbr>Module>(std::shared_ptr<Module<wbr>>)>;<br>
><br>
>    IRTransformLayer<decltype(Comp<wbr>ileLayer), OptimizeFunction> OptimizeLayer;<br>
><br>
>  public:<br>
> -  using ModuleHandle = decltype(OptimizeLayer)::Modul<wbr>eSetHandleT;<br>
> +  using ModuleHandle = decltype(OptimizeLayer)::Modul<wbr>eHandleT;<br>
><br>
>    KaleidoscopeJIT()<br>
>        : TM(EngineBuilder().selectTarge<wbr>t()), DL(TM->createDataLayout()),<br>
>          CompileLayer(ObjectLayer, SimpleCompiler(*TM)),<br>
>          OptimizeLayer(CompileLayer,<br>
> -                      [this](std::unique_ptr<Module> M) {<br>
> +                      [this](std::shared_ptr<Module> M) {<br>
>                          return optimizeModule(std::move(M));<br>
>                        }) {<br>
>      llvm::sys::DynamicLibrary::Loa<wbr>dLibraryPermanently(nullptr);<br>
> @@ -85,15 +85,11 @@ public:<br>
>            return JITSymbol(nullptr);<br>
>          });<br>
><br>
> -    // Build a singleton module set to hold our module.<br>
> -    std::vector<std::unique_ptr<Mo<wbr>dule>> Ms;<br>
> -    Ms.push_back(std::move(M));<br>
> -<br>
>      // Add the set to the JIT with the resolver we created above and a newly<br>
>      // created SectionMemoryManager.<br>
> -    return OptimizeLayer.addModuleSet(std<wbr>::move(Ms),<br>
> -                                      make_unique<SectionMemoryManag<wbr>er>(),<br>
> -                                      std::move(Resolver));<br>
> +    return OptimizeLayer.addModule(std::m<wbr>ove(M),<br>
> +                                   make_unique<SectionMemoryMana<wbr>ger>(),<br>
> +                                   std::move(Resolver));<br>
>    }<br>
><br>
>    JITSymbol findSymbol(const std::string Name) {<br>
> @@ -104,11 +100,11 @@ public:<br>
>    }<br>
><br>
>    void removeModule(ModuleHandle H) {<br>
> -    OptimizeLayer.removeModuleSet(<wbr>H);<br>
> +    OptimizeLayer.removeModule(H);<br>
>    }<br>
><br>
>  private:<br>
> -  std::unique_ptr<Module> optimizeModule(std::unique_ptr<wbr><Module> M) {<br>
> +  std::shared_ptr<Module> optimizeModule(std::shared_ptr<wbr><Module> M) {<br>
>      // Create a function pass manager.<br>
>      auto FPM = llvm::make_unique<legacy::Func<wbr>tionPassManager>(M.get());<br>
><br>
><br>
> Modified: llvm/trunk/examples/Kaleidosco<wbr>pe/BuildingAJIT/Chapter3/Kalei<wbr>doscopeJIT.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h?rev=306166&r1=306165&r2=306166&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/examples/Kale<wbr>idoscope/BuildingAJIT/Chapter3<wbr>/KaleidoscopeJIT.h?rev=306166&<wbr>r1=306165&r2=306166&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/examples/Kaleidosco<wbr>pe/BuildingAJIT/Chapter3/Kalei<wbr>doscopeJIT.h (original)<br>
> +++ llvm/trunk/examples/Kaleidosco<wbr>pe/BuildingAJIT/Chapter3/Kalei<wbr>doscopeJIT.h Fri Jun 23 16:45:29 2017<br>
> @@ -51,7 +51,7 @@ private:<br>
>    IRCompileLayer<decltype(Object<wbr>Layer), SimpleCompiler> CompileLayer;<br>
><br>
>    using OptimizeFunction =<br>
> -      std::function<std::unique_ptr<<wbr>Module>(std::unique_ptr<Module<wbr>>)>;<br>
> +      std::function<std::shared_ptr<<wbr>Module>(std::shared_ptr<Module<wbr>>)>;<br>
><br>
>    IRTransformLayer<decltype(Comp<wbr>ileLayer), OptimizeFunction> OptimizeLayer;<br>
><br>
> @@ -59,13 +59,13 @@ private:<br>
>    CompileOnDemandLayer<decltype(<wbr>OptimizeLayer)> CODLayer;<br>
><br>
>  public:<br>
> -  using ModuleHandle = decltype(CODLayer)::ModuleSetH<wbr>andleT;<br>
> +  using ModuleHandle = decltype(CODLayer)::ModuleHand<wbr>leT;<br>
><br>
>    KaleidoscopeJIT()<br>
>        : TM(EngineBuilder().selectTarge<wbr>t()), DL(TM->createDataLayout()),<br>
>          CompileLayer(ObjectLayer, SimpleCompiler(*TM)),<br>
>          OptimizeLayer(CompileLayer,<br>
> -                      [this](std::unique_ptr<Module> M) {<br>
> +                      [this](std::shared_ptr<Module> M) {<br>
>                          return optimizeModule(std::move(M));<br>
>                        }),<br>
>          CompileCallbackManager(<br>
> @@ -98,15 +98,11 @@ public:<br>
>            return JITSymbol(nullptr);<br>
>          });<br>
><br>
> -    // Build a singleton module set to hold our module.<br>
> -    std::vector<std::unique_ptr<Mo<wbr>dule>> Ms;<br>
> -    Ms.push_back(std::move(M));<br>
> -<br>
>      // Add the set to the JIT with the resolver we created above and a newly<br>
>      // created SectionMemoryManager.<br>
> -    return CODLayer.addModuleSet(std::mov<wbr>e(Ms),<br>
> -                                 make_unique<SectionMemoryMana<wbr>ger>(),<br>
> -                                 std::move(Resolver));<br>
> +    return CODLayer.addModule(std::move(M<wbr>),<br>
> +                              make_unique<SectionMemoryManag<wbr>er>(),<br>
> +                              std::move(Resolver));<br>
>    }<br>
><br>
>    JITSymbol findSymbol(const std::string Name) {<br>
> @@ -117,11 +113,11 @@ public:<br>
>    }<br>
><br>
>    void removeModule(ModuleHandle H) {<br>
> -    CODLayer.removeModuleSet(H);<br>
> +    CODLayer.removeModule(H);<br>
>    }<br>
><br>
>  private:<br>
> -  std::unique_ptr<Module> optimizeModule(std::unique_ptr<wbr><Module> M) {<br>
> +  std::shared_ptr<Module> optimizeModule(std::shared_ptr<wbr><Module> M) {<br>
>      // Create a function pass manager.<br>
>      auto FPM = llvm::make_unique<legacy::Func<wbr>tionPassManager>(M.get());<br>
><br>
><br>
> Modified: llvm/trunk/examples/Kaleidosco<wbr>pe/BuildingAJIT/Chapter4/Kalei<wbr>doscopeJIT.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h?rev=306166&r1=306165&r2=306166&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/examples/Kale<wbr>idoscope/BuildingAJIT/Chapter4<wbr>/KaleidoscopeJIT.h?rev=306166&<wbr>r1=306165&r2=306166&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/examples/Kaleidosco<wbr>pe/BuildingAJIT/Chapter4/Kalei<wbr>doscopeJIT.h (original)<br>
> +++ llvm/trunk/examples/Kaleidosco<wbr>pe/BuildingAJIT/Chapter4/Kalei<wbr>doscopeJIT.h Fri Jun 23 16:45:29 2017<br>
> @@ -77,7 +77,7 @@ private:<br>
>    IRCompileLayer<decltype(Object<wbr>Layer), SimpleCompiler> CompileLayer;<br>
><br>
>    using OptimizeFunction =<br>
> -      std::function<std::unique_ptr<<wbr>Module>(std::unique_ptr<Module<wbr>>)>;<br>
> +      std::function<std::shared_ptr<<wbr>Module>(std::shared_ptr<Module<wbr>>)>;<br>
><br>
>    IRTransformLayer<decltype(Comp<wbr>ileLayer), OptimizeFunction> OptimizeLayer;<br>
><br>
> @@ -85,14 +85,14 @@ private:<br>
>    std::unique_ptr<IndirectStubsM<wbr>anager> IndirectStubsMgr;<br>
><br>
>  public:<br>
> -  using ModuleHandle = decltype(OptimizeLayer)::Modul<wbr>eSetHandleT;<br>
> +  using ModuleHandle = decltype(OptimizeLayer)::Modul<wbr>eHandleT;<br>
><br>
>    KaleidoscopeJIT()<br>
>        : TM(EngineBuilder().selectTarge<wbr>t()),<br>
>          DL(TM->createDataLayout()),<br>
>          CompileLayer(ObjectLayer, SimpleCompiler(*TM)),<br>
>          OptimizeLayer(CompileLayer,<br>
> -                      [this](std::unique_ptr<Module> M) {<br>
> +                      [this](std::shared_ptr<Module> M) {<br>
>                          return optimizeModule(std::move(M));<br>
>                        }),<br>
>          CompileCallbackMgr(<br>
> @@ -125,15 +125,11 @@ public:<br>
>            return JITSymbol(nullptr);<br>
>          });<br>
><br>
> -    // Build a singleton module set to hold our module.<br>
> -    std::vector<std::unique_ptr<Mo<wbr>dule>> Ms;<br>
> -    Ms.push_back(std::move(M));<br>
> -<br>
>      // Add the set to the JIT with the resolver we created above and a newly<br>
>      // created SectionMemoryManager.<br>
> -    return OptimizeLayer.addModuleSet(std<wbr>::move(Ms),<br>
> -                                      make_unique<SectionMemoryManag<wbr>er>(),<br>
> -                                      std::move(Resolver));<br>
> +    return OptimizeLayer.addModule(std::m<wbr>ove(M),<br>
> +                                   make_unique<SectionMemoryMana<wbr>ger>(),<br>
> +                                   std::move(Resolver));<br>
>    }<br>
><br>
>    Error addFunctionAST(std::unique_ptr<wbr><FunctionAST> FnAST) {<br>
> @@ -199,7 +195,7 @@ public:<br>
>    }<br>
><br>
>    void removeModule(ModuleHandle H) {<br>
> -    OptimizeLayer.removeModuleSet(<wbr>H);<br>
> +    OptimizeLayer.removeModule(H);<br>
>    }<br>
><br>
>  private:<br>
> @@ -210,7 +206,7 @@ private:<br>
>      return MangledNameStream.str();<br>
>    }<br>
><br>
> -  std::unique_ptr<Module> optimizeModule(std::unique_ptr<wbr><Module> M) {<br>
> +  std::shared_ptr<Module> optimizeModule(std::shared_ptr<wbr><Module> M) {<br>
>      // Create a function pass manager.<br>
>      auto FPM = llvm::make_unique<legacy::Func<wbr>tionPassManager>(M.get());<br>
><br>
><br>
> Modified: llvm/trunk/examples/Kaleidosco<wbr>pe/BuildingAJIT/Chapter5/Kalei<wbr>doscopeJIT.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h?rev=306166&r1=306165&r2=306166&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/examples/Kale<wbr>idoscope/BuildingAJIT/Chapter5<wbr>/KaleidoscopeJIT.h?rev=306166&<wbr>r1=306165&r2=306166&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/examples/Kaleidosco<wbr>pe/BuildingAJIT/Chapter5/Kalei<wbr>doscopeJIT.h (original)<br>
> +++ llvm/trunk/examples/Kaleidosco<wbr>pe/BuildingAJIT/Chapter5/Kalei<wbr>doscopeJIT.h Fri Jun 23 16:45:29 2017<br>
> @@ -82,7 +82,7 @@ private:<br>
>    IRCompileLayer<decltype(Object<wbr>Layer), SimpleCompiler> CompileLayer;<br>
><br>
>    using OptimizeFunction =<br>
> -      std::function<std::unique_ptr<<wbr>Module>(std::unique_ptr<Module<wbr>>)>;<br>
> +      std::function<std::shared_ptr<<wbr>Module>(std::shared_ptr<Module<wbr>>)>;<br>
><br>
>    IRTransformLayer<decltype(Comp<wbr>ileLayer), OptimizeFunction> OptimizeLayer;<br>
><br>
> @@ -91,7 +91,7 @@ private:<br>
>    MyRemote &Remote;<br>
><br>
>  public:<br>
> -  using ModuleHandle = decltype(OptimizeLayer)::Modul<wbr>eSetHandleT;<br>
> +  using ModuleHandle = decltype(OptimizeLayer)::Modul<wbr>eHandleT;<br>
><br>
>    KaleidoscopeJIT(MyRemote &Remote)<br>
>        : TM(EngineBuilder().selectTarge<wbr>t(Triple(Remote.getTargetTripl<wbr>e()), "",<br>
> @@ -99,7 +99,7 @@ public:<br>
>          DL(TM->createDataLayout()),<br>
>          CompileLayer(ObjectLayer, SimpleCompiler(*TM)),<br>
>          OptimizeLayer(CompileLayer,<br>
> -                      [this](std::unique_ptr<Module> M) {<br>
> +                      [this](std::shared_ptr<Module> M) {<br>
>                          return optimizeModule(std::move(M));<br>
>                        }),<br>
>          Remote(Remote) {<br>
> @@ -153,15 +153,11 @@ public:<br>
>        exit(1);<br>
>      }<br>
><br>
> -    // Build a singleton module set to hold our module.<br>
> -    std::vector<std::unique_ptr<Mo<wbr>dule>> Ms;<br>
> -    Ms.push_back(std::move(M));<br>
> -<br>
>      // Add the set to the JIT with the resolver we created above and a newly<br>
>      // created SectionMemoryManager.<br>
> -    return OptimizeLayer.addModuleSet(std<wbr>::move(Ms),<br>
> -                                      std::move(MemMgr),<br>
> -                                      std::move(Resolver));<br>
> +    return OptimizeLayer.addModule(std::m<wbr>ove(M),<br>
> +                                   std::move(MemMgr),<br>
> +                                   std::move(Resolver));<br>
>    }<br>
><br>
>    Error addFunctionAST(std::unique_ptr<wbr><FunctionAST> FnAST) {<br>
> @@ -231,7 +227,7 @@ public:<br>
>    }<br>
><br>
>    void removeModule(ModuleHandle H) {<br>
> -    OptimizeLayer.removeModuleSet(<wbr>H);<br>
> +    OptimizeLayer.removeModule(H);<br>
>    }<br>
><br>
>  private:<br>
> @@ -242,7 +238,7 @@ private:<br>
>      return MangledNameStream.str();<br>
>    }<br>
><br>
> -  std::unique_ptr<Module> optimizeModule(std::unique_ptr<wbr><Module> M) {<br>
> +  std::shared_ptr<Module> optimizeModule(std::shared_ptr<wbr><Module> M) {<br>
>      // Create a function pass manager.<br>
>      auto FPM = llvm::make_unique<legacy::Func<wbr>tionPassManager>(M.get());<br>
><br>
><br>
> Modified: llvm/trunk/examples/Kaleidosco<wbr>pe/include/KaleidoscopeJIT.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Kaleidoscope/include/KaleidoscopeJIT.h?rev=306166&r1=306165&r2=306166&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/examples/Kale<wbr>idoscope/include/KaleidoscopeJ<wbr>IT.h?rev=306166&r1=306165&r2=3<wbr>06166&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/examples/Kaleidosco<wbr>pe/include/KaleidoscopeJIT.h (original)<br>
> +++ llvm/trunk/examples/Kaleidosco<wbr>pe/include/KaleidoscopeJIT.h Fri Jun 23 16:45:29 2017<br>
> @@ -41,7 +41,7 @@ class KaleidoscopeJIT {<br>
>  public:<br>
>    using ObjLayerT = RTDyldObjectLinkingLayer;<br>
>    using CompileLayerT = IRCompileLayer<ObjLayerT, SimpleCompiler>;<br>
> -  using ModuleHandleT = CompileLayerT::ModuleSetHandle<wbr>T;<br>
> +  using ModuleHandleT = CompileLayerT::ModuleHandleT;<br>
><br>
>    KaleidoscopeJIT()<br>
>        : TM(EngineBuilder().selectTarge<wbr>t()), DL(TM->createDataLayout()),<br>
> @@ -62,9 +62,9 @@ public:<br>
>            return JITSymbol(nullptr);<br>
>          },<br>
>          [](const std::string &S) { return nullptr; });<br>
> -    auto H = CompileLayer.addModuleSet(sing<wbr>letonSet(std::move(M)),<br>
> -                                       make_unique<SectionMemoryMana<wbr>ger>(),<br>
> -                                       std::move(Resolver));<br>
> +    auto H = CompileLayer.addModule(std::mo<wbr>ve(M),<br>
> +                                    make_unique<SectionMemoryManag<wbr>er>(),<br>
> +                                    std::move(Resolver));<br>
><br>
>      ModuleHandles.push_back(H);<br>
>      return H;<br>
> @@ -72,7 +72,7 @@ public:<br>
><br>
>    void removeModule(ModuleHandleT H) {<br>
>      ModuleHandles.erase(find(Modul<wbr>eHandles, H));<br>
> -    CompileLayer.removeModuleSet(H<wbr>);<br>
> +    CompileLayer.removeModule(H);<br>
>    }<br>
><br>
>    JITSymbol findSymbol(const std::string Name) {<br>
> @@ -89,12 +89,6 @@ private:<br>
>      return MangledName;<br>
>    }<br>
><br>
> -  template <typename T> static std::vector<T> singletonSet(T t) {<br>
> -    std::vector<T> Vec;<br>
> -    Vec.push_back(std::move(t));<br>
> -    return Vec;<br>
> -  }<br>
> -<br>
>    JITSymbol findMangledSymbol(const std::string &Name) {<br>
>  #ifdef LLVM_ON_WIN32<br>
>      // The symbol lookup of ObjectLinkingLayer uses the SymbolRef::SF_Exported<br>
><br>
> Modified: llvm/trunk/include/llvm-c/OrcB<wbr>indings.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/OrcBindings.h?rev=306166&r1=306165&r2=306166&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/include/llvm-<wbr>c/OrcBindings.h?rev=306166&r1=<wbr>306165&r2=306166&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/include/llvm-c/OrcB<wbr>indings.h (original)<br>
> +++ llvm/trunk/include/llvm-c/OrcB<wbr>indings.h Fri Jun 23 16:45:29 2017<br>
> @@ -29,6 +29,8 @@<br>
>  extern "C" {<br>
>  #endif<br>
><br>
> +typedef struct LLVMOpaqueSharedModule *LLVMSharedModuleRef;<br>
> +typedef struct LLVMOpaqueSharedObjectBuffer *LLVMSharedObjectBufferRef;<br>
>  typedef struct LLVMOrcOpaqueJITStack *LLVMOrcJITStackRef;<br>
>  typedef uint32_t LLVMOrcModuleHandle;<br>
>  typedef uint64_t LLVMOrcTargetAddress;<br>
> @@ -39,6 +41,45 @@ typedef uint64_t (*LLVMOrcLazyCompileCal<br>
>  typedef enum { LLVMOrcErrSuccess = 0, LLVMOrcErrGeneric } LLVMOrcErrorCode;<br>
><br>
>  /**<br>
> + * Turn an LLVMModuleRef into an LLVMSharedModuleRef.<br>
> + *<br>
> + * The JIT uses shared ownership for LLVM modules, since it is generally<br>
> + * difficult to know when the JIT will be finished with a module (and the JIT<br>
> + * has no way of knowing when a user may be finished with one).<br>
> + *<br>
> + * Calling this method with an LLVMModuleRef creates a shared-pointer to the<br>
> + * module, and returns a reference to this shared pointer.<br>
> + *<br>
> + * The shared module should be disposed when finished with by calling<br>
> + * LLVMOrcDisposeSharedModule (not LLVMDisposeModule). The Module will be<br>
> + * deleted when the last shared pointer owner relinquishes it.<br>
> + */<br>
> +<br>
> +LLVMSharedModuleRef LLVMOrcMakeSharedModule(LLVMMo<wbr>duleRef Mod);<br>
> +<br>
> +/**<br>
> + * Dispose of a shared module.<br>
> + *<br>
> + * The module should not be accessed after this call. The module will be<br>
> + * deleted once all clients (including the JIT itself) have released their<br>
> + * shared pointers.<br>
> + */<br>
> +<br>
> +void LLVMOrcDisposeSharedModuleRef(<wbr>LLVMSharedModuleRef SharedMod);<br>
> +<br>
> +/**<br>
> + * Get an LLVMSharedObjectBufferRef from an LLVMMemoryBufferRef.<br>
> + */<br>
> +LLVMSharedObjectBufferRef<br>
> +LLVMOrcMakeSharedObjectBuffer<wbr>(LLVMMemoryBufferRef ObjBuffer);<br>
> +<br>
> +/**<br>
> + * Dispose of a shared object buffer.<br>
> + */<br>
> +void<br>
> +LLVMOrcDisposeSharedObjectBuf<wbr>ferRef(LLVMSharedObjectBufferR<wbr>ef SharedObjBuffer);<br>
> +<br>
> +/**<br>
>   * Create an ORC JIT stack.<br>
>   *<br>
>   * The client owns the resulting stack, and must call OrcDisposeInstance(...)<br>
> @@ -95,7 +136,8 @@ LLVMOrcErrorCode LLVMOrcSetIndirectStubP<br>
>   * Add module to be eagerly compiled.<br>
>   */<br>
>  LLVMOrcModuleHandle<br>
> -LLVMOrcAddEagerlyCompiledIR(L<wbr>LVMOrcJITStackRef JITStack, LLVMModuleRef Mod,<br>
> +LLVMOrcAddEagerlyCompiledIR(L<wbr>LVMOrcJITStackRef JITStack,<br>
> +                            LLVMSharedModuleRef Mod,<br>
>                              LLVMOrcSymbolResolverFn SymbolResolver,<br>
>                              void *SymbolResolverCtx);<br>
><br>
> @@ -103,7 +145,8 @@ LLVMOrcAddEagerlyCompiledIR(LL<wbr>VMOrcJITSt<br>
>   * Add module to be lazily compiled one function at a time.<br>
>   */<br>
>  LLVMOrcModuleHandle<br>
> -LLVMOrcAddLazilyCompiledIR(LL<wbr>VMOrcJITStackRef JITStack, LLVMModuleRef Mod,<br>
> +LLVMOrcAddLazilyCompiledIR(LL<wbr>VMOrcJITStackRef JITStack,<br>
> +                           LLVMSharedModuleRef Mod,<br>
>                             LLVMOrcSymbolResolverFn SymbolResolver,<br>
>                             void *SymbolResolverCtx);<br>
><br>
> @@ -111,7 +154,7 @@ LLVMOrcAddLazilyCompiledIR(LLV<wbr>MOrcJITSta<br>
>   * Add an object file.<br>
>   */<br>
>  LLVMOrcModuleHandle LLVMOrcAddObjectFile(LLVMOrcJI<wbr>TStackRef JITStack,<br>
> -                                         LLVMObjectFileRef Obj,<br>
> +                                         LLVMSharedObjectBufferRef Obj,<br>
>                                           LLVMOrcSymbolResolverFn SymbolResolver,<br>
>                                           void *SymbolResolverCtx);<br>
><br>
><br>
> Modified: llvm/trunk/include/llvm/Execut<wbr>ionEngine/Orc/CompileOnDemandL<wbr>ayer.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h?rev=306166&r1=306165&r2=306166&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/include/llvm/<wbr>ExecutionEngine/Orc/CompileOnD<wbr>emandLayer.h?rev=306166&r1=306<wbr>165&r2=306166&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/include/llvm/Execut<wbr>ionEngine/Orc/CompileOnDemandL<wbr>ayer.h (original)<br>
> +++ llvm/trunk/include/llvm/Execut<wbr>ionEngine/Orc/CompileOnDemandL<wbr>ayer.h Fri Jun 23 16:45:29 2017<br>
> @@ -84,7 +84,7 @@ private:<br>
>      return LambdaMaterializer<Materialize<wbr>rFtor>(std::move(M));<br>
>    }<br>
><br>
> -  using BaseLayerModuleSetHandleT = typename BaseLayerT::ModuleSetHandleT;<br>
> +  using BaseLayerModuleHandleT = typename BaseLayerT::ModuleHandleT;<br>
><br>
>    // Provide type-erasure for the Modules and MemoryManagers.<br>
>    template <typename ResourceT><br>
> @@ -139,9 +139,11 @@ private:<br>
>    struct LogicalDylib {<br>
>      using SymbolResolverFtor = std::function<JITSymbol(const std::string&)>;<br>
><br>
> -    using ModuleAdderFtor = std::function<typename BaseLayerT::ModuleSetHandleT(<br>
> -        BaseLayerT &, std::unique_ptr<Module>,<br>
> -        std::unique_ptr<JITSymbolResol<wbr>ver>)>;<br>
> +    using ModuleAdderFtor =<br>
> +      std::function<typename BaseLayerT::ModuleHandleT(<br>
> +                    BaseLayerT&,<br>
> +                    std::unique_ptr<Module>,<br>
> +                    std::unique_ptr<JITSymbolResol<wbr>ver>)>;<br>
><br>
>      struct SourceModuleEntry {<br>
>        std::unique_ptr<ResourceOwner<<wbr>Module>> SourceMod;<br>
> @@ -179,7 +181,7 @@ private:<br>
><br>
>      void removeModulesFromBaseLayer(Bas<wbr>eLayerT &BaseLayer) {<br>
>        for (auto &BLH : BaseLayerHandles)<br>
> -        BaseLayer.removeModuleSet(BLH)<wbr>;<br>
> +        BaseLayer.removeModule(BLH);<br>
>      }<br>
><br>
>      std::unique_ptr<JITSymbolResol<wbr>ver> ExternalSymbolResolver;<br>
> @@ -188,14 +190,14 @@ private:<br>
>      StaticGlobalRenamer StaticRenamer;<br>
>      ModuleAdderFtor ModuleAdder;<br>
>      SourceModulesList SourceModules;<br>
> -    std::vector<BaseLayerModuleSet<wbr>HandleT> BaseLayerHandles;<br>
> +    std::vector<BaseLayerModuleHan<wbr>dleT> BaseLayerHandles;<br>
>    };<br>
><br>
>    using LogicalDylibList = std::list<LogicalDylib>;<br>
><br>
>  public:<br>
> -  /// @brief Handle to a set of loaded modules.<br>
> -  using ModuleSetHandleT = typename LogicalDylibList::iterator;<br>
> +  /// @brief Handle to loaded module.<br>
> +  using ModuleHandleT = typename LogicalDylibList::iterator;<br>
><br>
>    /// @brief Module partitioning functor.<br>
>    using PartitioningFtor = std::function<std::set<Functio<wbr>n*>(Function&)>;<br>
> @@ -216,15 +218,15 @@ public:<br>
><br>
>    ~CompileOnDemandLayer() {<br>
>      while (!LogicalDylibs.empty())<br>
> -      removeModuleSet(LogicalDylibs.<wbr>begin());<br>
> +      removeModule(LogicalDylibs.beg<wbr>in());<br>
>    }<br>
> -<br>
> +<br>
>    /// @brief Add a module to the compile-on-demand layer.<br>
> -  template <typename ModuleSetT, typename MemoryManagerPtrT,<br>
> -            typename SymbolResolverPtrT><br>
> -  ModuleSetHandleT addModuleSet(ModuleSetT Ms,<br>
> -                                MemoryManagerPtrT MemMgr,<br>
> -                                SymbolResolverPtrT Resolver) {<br>
> +  template <typename MemoryManagerPtrT, typename SymbolResolverPtrT><br>
> +  ModuleHandleT addModule(std::shared_ptr<Modu<wbr>le> M,<br>
> +                          MemoryManagerPtrT MemMgr,<br>
> +                          SymbolResolverPtrT Resolver) {<br>
> +<br>
>      LogicalDylibs.push_back(Logica<wbr>lDylib());<br>
>      auto &LD = LogicalDylibs.back();<br>
>      LD.ExternalSymbolResolver = std::move(Resolver);<br>
> @@ -236,23 +238,25 @@ public:<br>
>      LD.ModuleAdder =<br>
>        [&MemMgrRef](BaseLayerT &B, std::unique_ptr<Module> M,<br>
>                     std::unique_ptr<JITSymbolReso<wbr>lver> R) {<br>
> -        std::vector<std::unique_ptr<Mo<wbr>dule>> Ms;<br>
> -        Ms.push_back(std::move(M));<br>
> -        return B.addModuleSet(std::move(Ms), &MemMgrRef, std::move(R));<br>
> +        return B.addModule(std::move(M), &MemMgrRef, std::move(R));<br>
>        };<br>
><br>
>      // Process each of the modules in this module set.<br>
> -    for (auto &M : Ms)<br>
> -      addLogicalModule(LogicalDylibs<wbr>.back(), std::move(M));<br>
> +    addLogicalModule(LogicalDylibs<wbr>.back(), std::move(M));<br>
><br>
>      return std::prev(LogicalDylibs.end())<wbr>;<br>
>    }<br>
><br>
> +  /// @brief Add extra modules to an existing logical module.<br>
> +  void addExtraModule(ModuleHandleT H, std::shared_ptr<Module> M) {<br>
> +    addLogicalModule(*H, std::move(M));<br>
> +  }<br>
> +<br>
>    /// @brief Remove the module represented by the given handle.<br>
>    ///<br>
>    ///   This will remove all modules in the layers below that were derived from<br>
>    /// the module represented by H.<br>
> -  void removeModuleSet(ModuleSetHandl<wbr>eT H) {<br>
> +  void removeModule(ModuleHandleT H) {<br>
>      H->removeModulesFromBaseLayer(<wbr>BaseLayer);<br>
>      LogicalDylibs.erase(H);<br>
>    }<br>
> @@ -274,7 +278,7 @@ public:<br>
><br>
>    /// @brief Get the address of a symbol provided by this layer, or some layer<br>
>    ///        below this one.<br>
> -  JITSymbol findSymbolIn(ModuleSetHandleT H, const std::string &Name,<br>
> +  JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name,<br>
>                           bool ExportedSymbolsOnly) {<br>
>      return H->findSymbol(BaseLayer, Name, ExportedSymbolsOnly);<br>
>    }<br>
> @@ -498,7 +502,7 @@ private:<br>
>    }<br>
><br>
>    template <typename PartitionT><br>
> -  BaseLayerModuleSetHandleT<br>
> +  BaseLayerModuleHandleT<br>
>    emitPartition(LogicalDylib &LD,<br>
>                  typename LogicalDylib::SourceModuleHand<wbr>le LMId,<br>
>                  const PartitionT &Part) {<br>
><br>
> Modified: llvm/trunk/include/llvm/Execut<wbr>ionEngine/Orc/ExecutionUtils.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h?rev=306166&r1=306165&r2=306166&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/include/llvm/<wbr>ExecutionEngine/Orc/ExecutionU<wbr>tils.h?rev=306166&r1=306165&r2<wbr>=306166&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/include/llvm/Execut<wbr>ionEngine/Orc/ExecutionUtils.h (original)<br>
> +++ llvm/trunk/include/llvm/Execut<wbr>ionEngine/Orc/ExecutionUtils.h Fri Jun 23 16:45:29 2017<br>
> @@ -94,7 +94,7 @@ public:<br>
>    /// @brief Construct a CtorDtorRunner for the given range using the given<br>
>    ///        name mangling function.<br>
>    CtorDtorRunner(std::vector<std<wbr>::string> CtorDtorNames,<br>
> -                 typename JITLayerT::ModuleSetHandleT H)<br>
> +                 typename JITLayerT::ModuleHandleT H)<br>
>        : CtorDtorNames(std::move(CtorDt<wbr>orNames)), H(H) {}<br>
><br>
>    /// @brief Run the recorded constructors/destructors through the given JIT<br>
> @@ -116,7 +116,7 @@ public:<br>
><br>
>  private:<br>
>    std::vector<std::string> CtorDtorNames;<br>
> -  typename JITLayerT::ModuleSetHandleT H;<br>
> +  typename JITLayerT::ModuleHandleT H;<br>
>  };<br>
><br>
>  /// @brief Support class for static dtor execution. For hosted (in-process) JITs<br>
><br>
> Modified: llvm/trunk/include/llvm/Execut<wbr>ionEngine/Orc/IRCompileLayer.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h?rev=306166&r1=306165&r2=306166&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/include/llvm/<wbr>ExecutionEngine/Orc/IRCompileL<wbr>ayer.h?rev=306166&r1=306165&r2<wbr>=306166&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/include/llvm/Execut<wbr>ionEngine/Orc/IRCompileLayer.h (original)<br>
> +++ llvm/trunk/include/llvm/Execut<wbr>ionEngine/Orc/IRCompileLayer.h Fri Jun 23 16:45:29 2017<br>
> @@ -28,15 +28,15 @@ namespace orc {<br>
><br>
>  /// @brief Eager IR compiling layer.<br>
>  ///<br>
> -///   This layer accepts sets of LLVM IR Modules (via addModuleSet). It<br>
> -/// immediately compiles each IR module to an object file (each IR Module is<br>
> -/// compiled separately). The resulting set of object files is then added to<br>
> -/// the layer below, which must implement the object layer concept.<br>
> +///   This layer immediately compiles each IR module added via addModule to an<br>
> +/// object file and adds this module file to the layer below, which must<br>
> +/// implement the object layer concept.<br>
>  template <typename BaseLayerT, typename CompileFtor><br>
>  class IRCompileLayer {<br>
>  public:<br>
> -  /// @brief Handle to a set of compiled modules.<br>
> -  using ModuleSetHandleT = typename BaseLayerT::ObjHandleT;<br>
> +<br>
> +  /// @brief Handle to a compiled module.<br>
> +  using ModuleHandleT = typename BaseLayerT::ObjHandleT;<br>
><br>
>    /// @brief Construct an IRCompileLayer with the given BaseLayer, which must<br>
>    ///        implement the ObjectLayer concept.<br>
> @@ -46,25 +46,22 @@ public:<br>
>    /// @brief Get a reference to the compiler functor.<br>
>    CompileFtor& getCompiler() { return Compile; }<br>
><br>
> -  /// @brief Compile each module in the given module set, then add the resulting<br>
> -  ///        set of objects to the base layer along with the memory manager and<br>
> -  ///        symbol resolver.<br>
> +  /// @brief Compile the module, and add the resulting object to the base layer<br>
> +  ///        along with the given memory manager and symbol resolver.<br>
>    ///<br>
> -  /// @return A handle for the added modules.<br>
> -  template <typename ModuleSetT, typename MemoryManagerPtrT,<br>
> -            typename SymbolResolverPtrT><br>
> -  ModuleSetHandleT addModuleSet(ModuleSetT Ms,<br>
> -                                MemoryManagerPtrT MemMgr,<br>
> -                                SymbolResolverPtrT Resolver) {<br>
> -    assert(Ms.size() == 1);<br>
> -    using CompileResult = decltype(Compile(*Ms.front()))<wbr>;<br>
> -    auto Obj = std::make_shared<CompileResult<wbr>>(Compile(*Ms.front()));<br>
> +  /// @return A handle for the added module.<br>
> +  template <typename MemoryManagerPtrT, typename SymbolResolverPtrT><br>
> +  ModuleHandleT addModule(std::shared_ptr<Modu<wbr>le> M,<br>
> +                          MemoryManagerPtrT MemMgr,<br>
> +                          SymbolResolverPtrT Resolver) {<br>
> +    using CompileResult = decltype(Compile(*M));<br>
> +    auto Obj = std::make_shared<CompileResult<wbr>>(Compile(*M));<br>
>      return BaseLayer.addObject(std::move(<wbr>Obj), std::move(MemMgr),<br>
>                                 std::move(Resolver));<br>
>    }<br>
><br>
> -  /// @brief Remove the module set associated with the handle H.<br>
> -  void removeModuleSet(ModuleSetHandl<wbr>eT H) { BaseLayer.removeObject(H); }<br>
> +  /// @brief Remove the module associated with the handle H.<br>
> +  void removeModule(ModuleHandleT H) { BaseLayer.removeObject(H); }<br>
><br>
>    /// @brief Search for the given named symbol.<br>
>    /// @param Name The name of the symbol to search for.<br>
> @@ -74,23 +71,23 @@ public:<br>
>      return BaseLayer.findSymbol(Name, ExportedSymbolsOnly);<br>
>    }<br>
><br>
> -  /// @brief Get the address of the given symbol in the context of the set of<br>
> -  ///        compiled modules represented by the handle H. This call is<br>
> -  ///        forwarded to the base layer's implementation.<br>
> -  /// @param H The handle for the module set to search in.<br>
> +  /// @brief Get the address of the given symbol in compiled module represented<br>
> +  ///        by the handle H. This call is forwarded to the base layer's<br>
> +  ///        implementation.<br>
> +  /// @param H The handle for the module to search in.<br>
>    /// @param Name The name of the symbol to search for.<br>
>    /// @param ExportedSymbolsOnly If true, search only for exported symbols.<br>
>    /// @return A handle for the given named symbol, if it is found in the<br>
> -  ///         given module set.<br>
> -  JITSymbol findSymbolIn(ModuleSetHandleT H, const std::string &Name,<br>
> +  ///         given module.<br>
> +  JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name,<br>
>                           bool ExportedSymbolsOnly) {<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(ModuleSetHandl<wbr>eT H) {<br>
> +  /// @brief Immediately emit and finalize the module represented by the given<br>
> +  ///        handle.<br>
> +  /// @param H Handle for module to emit/finalize.<br>
> +  void emitAndFinalize(ModuleHandleT H) {<br>
>      BaseLayer.emitAndFinalize(H);<br>
>    }<br>
><br>
><br>
> Modified: llvm/trunk/include/llvm/Execut<wbr>ionEngine/Orc/IRTransformLayer<wbr>.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/IRTransformLayer.h?rev=306166&r1=306165&r2=306166&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/include/llvm/<wbr>ExecutionEngine/Orc/IRTransfor<wbr>mLayer.h?rev=306166&r1=306165&<wbr>r2=306166&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/include/llvm/Execut<wbr>ionEngine/Orc/IRTransformLayer<wbr>.h (original)<br>
> +++ llvm/trunk/include/llvm/Execut<wbr>ionEngine/Orc/IRTransformLayer<wbr>.h Fri Jun 23 16:45:29 2017<br>
> @@ -22,39 +22,34 @@ namespace orc {<br>
><br>
>  /// @brief IR mutating layer.<br>
>  ///<br>
> -///   This layer accepts sets of LLVM IR Modules (via addModuleSet). It<br>
> -/// immediately applies the user supplied functor to each module, then adds<br>
> -/// the set of transformed modules to the layer below.<br>
> +///   This layer applies a user supplied transform to each module that is added,<br>
> +/// then adds the transformed module to the layer below.<br>
>  template <typename BaseLayerT, typename TransformFtor><br>
>  class IRTransformLayer {<br>
>  public:<br>
> +<br>
>    /// @brief Handle to a set of added modules.<br>
> -  using ModuleSetHandleT = typename BaseLayerT::ModuleSetHandleT;<br>
> +  using ModuleHandleT = typename BaseLayerT::ModuleHandleT;<br>
><br>
>    /// @brief Construct an IRTransformLayer with the given BaseLayer<br>
>    IRTransformLayer(BaseLayerT &BaseLayer,<br>
>                     TransformFtor Transform = TransformFtor())<br>
>      : BaseLayer(BaseLayer), Transform(std::move(Transform)<wbr>) {}<br>
><br>
> -  /// @brief Apply the transform functor to each module in the module set, then<br>
> -  ///        add the resulting set of modules to the base layer, along with the<br>
> -  ///        memory manager and symbol resolver.<br>
> +  /// @brief Apply the transform functor to the module, then add the module to<br>
> +  ///        the layer below, along with the memory manager and symbol resolver.<br>
>    ///<br>
>    /// @return A handle for the added modules.<br>
> -  template <typename ModuleSetT, typename MemoryManagerPtrT,<br>
> -            typename SymbolResolverPtrT><br>
> -  ModuleSetHandleT addModuleSet(ModuleSetT Ms,<br>
> -                                MemoryManagerPtrT MemMgr,<br>
> -                                SymbolResolverPtrT Resolver) {<br>
> -    for (auto I = Ms.begin(), E = Ms.end(); I != E; ++I)<br>
> -      *I = Transform(std::move(*I));<br>
> -<br>
> -    return BaseLayer.addModuleSet(std::mo<wbr>ve(Ms), std::move(MemMgr),<br>
> -                                  std::move(Resolver));<br>
> +  template <typename MemoryManagerPtrT, typename SymbolResolverPtrT><br>
> +  ModuleHandleT addModule(std::shared_ptr<Modu<wbr>le> M,<br>
> +                          MemoryManagerPtrT MemMgr,<br>
> +                          SymbolResolverPtrT Resolver) {<br>
> +    return BaseLayer.addModule(Transform(<wbr>std::move(M)), std::move(MemMgr),<br>
> +                               std::move(Resolver));<br>
>    }<br>
><br>
> -  /// @brief Remove the module set associated with the handle H.<br>
> -  void removeModuleSet(ModuleSetHandl<wbr>eT H) { BaseLayer.removeModuleSet(H); }<br>
> +  /// @brief Remove the module associated with the handle H.<br>
> +  void removeModule(ModuleHandleT H) { BaseLayer.removeModule(H); }<br>
><br>
>    /// @brief Search for the given named symbol.<br>
>    /// @param Name The name of the symbol to search for.<br>
> @@ -64,23 +59,23 @@ public:<br>
>      return BaseLayer.findSymbol(Name, ExportedSymbolsOnly);<br>
>    }<br>
><br>
> -  /// @brief Get the address of the given symbol in the context of the set of<br>
> -  ///        modules represented by the handle H. This call is forwarded to the<br>
> -  ///        base layer's implementation.<br>
> -  /// @param H The handle for the module set to search in.<br>
> +  /// @brief Get the address of the given symbol in the context of the module<br>
> +  ///        represented by the handle H. This call is forwarded to the base<br>
> +  ///        layer's implementation.<br>
> +  /// @param H The handle for the module to search in.<br>
>    /// @param Name The name of the symbol to search for.<br>
>    /// @param ExportedSymbolsOnly If true, search only for exported symbols.<br>
>    /// @return A handle for the given named symbol, if it is found in the<br>
> -  ///         given module set.<br>
> -  JITSymbol findSymbolIn(ModuleSetHandleT H, const std::string &Name,<br>
> +  ///         given module.<br>
> +  JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name,<br>
>                           bool ExportedSymbolsOnly) {<br>
>      return BaseLayer.findSymbolIn(H, Name, ExportedSymbolsOnly);<br>
>    }<br>
><br>
> -  /// @brief Immediately emit and finalize the module set represented by the<br>
> -  ///        given handle.<br>
> -  /// @param H Handle for module set to emit/finalize.<br>
> -  void emitAndFinalize(ModuleSetHandl<wbr>eT H) {<br>
> +  /// @brief Immediately emit and finalize the module represented by the given<br>
> +  ///        handle.<br>
> +  /// @param H Handle for module to emit/finalize.<br>
> +  void emitAndFinalize(ModuleHandleT H) {<br>
>      BaseLayer.emitAndFinalize(H);<br>
>    }<br>
><br>
><br>
> Modified: llvm/trunk/include/llvm/Execut<wbr>ionEngine/Orc/LazyEmittingLaye<wbr>r.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/LazyEmittingLayer.h?rev=306166&r1=306165&r2=306166&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/include/llvm/<wbr>ExecutionEngine/Orc/LazyEmitti<wbr>ngLayer.h?rev=306166&r1=306165<wbr>&r2=306166&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/include/llvm/Execut<wbr>ionEngine/Orc/LazyEmittingLaye<wbr>r.h (original)<br>
> +++ llvm/trunk/include/llvm/Execut<wbr>ionEngine/Orc/LazyEmittingLaye<wbr>r.h Fri Jun 23 16:45:29 2017<br>
> @@ -34,19 +34,20 @@ namespace orc {<br>
><br>
>  /// @brief Lazy-emitting IR layer.<br>
>  ///<br>
> -///   This layer accepts sets of LLVM IR Modules (via addModuleSet), but does<br>
> -/// not immediately emit them the layer below. Instead, emissing to the base<br>
> -/// layer is deferred until the first time the client requests the address<br>
> -/// (via JITSymbol::getAddress) for a symbol contained in this layer.<br>
> +///   This layer accepts LLVM IR Modules (via addModule), but does not<br>
> +/// immediately emit them the layer below. Instead, emissing to the base layer<br>
> +/// is deferred until the first time the client requests the address (via<br>
> +/// JITSymbol::getAddress) for a symbol contained in this layer.<br>
>  template <typename BaseLayerT> class LazyEmittingLayer {<br>
>  public:<br>
> -  using BaseLayerHandleT = typename BaseLayerT::ModuleSetHandleT;<br>
> +<br>
> +  using BaseLayerHandleT = typename BaseLayerT::ModuleHandleT;<br>
><br>
>  private:<br>
> -  class EmissionDeferredSet {<br>
> +  class EmissionDeferredModule {<br>
>    public:<br>
> -    EmissionDeferredSet() = default;<br>
> -    virtual ~EmissionDeferredSet() = default;<br>
> +    EmissionDeferredModule() = default;<br>
> +    virtual ~EmissionDeferredModule() = default;<br>
><br>
>      JITSymbol find(StringRef Name, bool ExportedSymbolsOnly, BaseLayerT &B) {<br>
>        switch (EmitState) {<br>
> @@ -84,9 +85,9 @@ private:<br>
>        llvm_unreachable("Invalid emit-state.");<br>
>      }<br>
><br>
> -    void removeModulesFromBaseLayer(Bas<wbr>eLayerT &BaseLayer) {<br>
> +    void removeModuleFromBaseLayer(Base<wbr>LayerT &BaseLayer) {<br>
>        if (EmitState != NotEmitted)<br>
> -        BaseLayer.removeModuleSet(Hand<wbr>le);<br>
> +        BaseLayer.removeModule(Handle)<wbr>;<br>
>      }<br>
><br>
>      void emitAndFinalize(BaseLayerT &BaseLayer) {<br>
> @@ -100,10 +101,9 @@ private:<br>
>        BaseLayer.emitAndFinalize(Hand<wbr>le);<br>
>      }<br>
><br>
> -    template <typename ModuleSetT, typename MemoryManagerPtrT,<br>
> -              typename SymbolResolverPtrT><br>
> -    static std::unique_ptr<EmissionDeferr<wbr>edSet><br>
> -    create(BaseLayerT &B, ModuleSetT Ms, MemoryManagerPtrT MemMgr,<br>
> +    template <typename MemoryManagerPtrT, typename SymbolResolverPtrT><br>
> +    static std::unique_ptr<EmissionDeferr<wbr>edModule><br>
> +    create(BaseLayerT &B, std::shared_ptr<Module> M, MemoryManagerPtrT MemMgr,<br>
>             SymbolResolverPtrT Resolver);<br>
><br>
>    protected:<br>
> @@ -116,14 +116,13 @@ private:<br>
>      BaseLayerHandleT Handle;<br>
>    };<br>
><br>
> -  template <typename ModuleSetT, typename MemoryManagerPtrT,<br>
> -            typename SymbolResolverPtrT><br>
> -  class EmissionDeferredSetImpl : public EmissionDeferredSet {<br>
> +  template <typename MemoryManagerPtrT, typename SymbolResolverPtrT><br>
> +  class EmissionDeferredModuleImpl : public EmissionDeferredModule {<br>
>    public:<br>
> -    EmissionDeferredSetImpl(Module<wbr>SetT Ms,<br>
> -                            MemoryManagerPtrT MemMgr,<br>
> -                            SymbolResolverPtrT Resolver)<br>
> -        : Ms(std::move(Ms)), MemMgr(std::move(MemMgr)),<br>
> +    EmissionDeferredModuleImpl(std<wbr>::shared_ptr<Module> M,<br>
> +                               MemoryManagerPtrT MemMgr,<br>
> +                               SymbolResolverPtrT Resolver)<br>
> +        : M(std::move(M)), MemMgr(std::move(MemMgr)),<br>
>            Resolver(std::move(Resolver)) {}<br>
><br>
>    protected:<br>
> @@ -154,8 +153,8 @@ private:<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>
>        MangledSymbols.reset();<br>
> -      return BaseLayer.addModuleSet(std::mo<wbr>ve(Ms), std::move(MemMgr),<br>
> -                                    std::move(Resolver));<br>
> +      return BaseLayer.addModule(std::move(<wbr>M), std::move(MemMgr),<br>
> +                                 std::move(Resolver));<br>
>      }<br>
><br>
>    private:<br>
> @@ -197,56 +196,54 @@ private:<br>
><br>
>        auto Symbols = llvm::make_unique<StringMap<co<wbr>nst GlobalValue*>>();<br>
><br>
> -      for (const auto &M : Ms) {<br>
> -        Mangler Mang;<br>
> +      Mangler Mang;<br>
><br>
> -        for (const auto &GO : M->global_objects())<br>
> +      for (const auto &GO : M->global_objects())<br>
>            if (auto GV = addGlobalValue(*Symbols, GO, Mang, SearchName,<br>
>                                         ExportedSymbolsOnly))<br>
>              return GV;<br>
> -      }<br>
><br>
>        MangledSymbols = std::move(Symbols);<br>
>        return nullptr;<br>
>      }<br>
><br>
> -    ModuleSetT Ms;<br>
> +    std::shared_ptr<Module> M;<br>
>      MemoryManagerPtrT MemMgr;<br>
>      SymbolResolverPtrT Resolver;<br>
>      mutable std::unique_ptr<StringMap<cons<wbr>t GlobalValue*>> MangledSymbols;<br>
>    };<br>
><br>
> -  using ModuleSetListT = std::list<std::unique_ptr<Emis<wbr>sionDeferredSet>>;<br>
> +  using ModuleListT = std::list<std::unique_ptr<Emis<wbr>sionDeferredModule>>;<br>
><br>
>    BaseLayerT &BaseLayer;<br>
> -  ModuleSetListT ModuleSetList;<br>
> +  ModuleListT ModuleList;<br>
><br>
>  public:<br>
> -  /// @brief Handle to a set of loaded modules.<br>
> -  using ModuleSetHandleT = typename ModuleSetListT::iterator;<br>
> +  /// @brief Handle to a loaded module.<br>
> +  using ModuleHandleT = typename ModuleListT::iterator;<br>
><br>
>    /// @brief Construct a lazy emitting layer.<br>
>    LazyEmittingLayer(BaseLayerT &BaseLayer) : BaseLayer(BaseLayer) {}<br>
><br>
> -  /// @brief Add the given set of modules to the lazy emitting layer.<br>
> -  template <typename ModuleSetT, typename MemoryManagerPtrT,<br>
> -            typename SymbolResolverPtrT><br>
> -  ModuleSetHandleT addModuleSet(ModuleSetT Ms,<br>
> -                                MemoryManagerPtrT MemMgr,<br>
> -                                SymbolResolverPtrT Resolver) {<br>
> -    return ModuleSetList.insert(<br>
> -        ModuleSetList.end(),<br>
> -        EmissionDeferredSet::create(Ba<wbr>seLayer, std::move(Ms), std::move(MemMgr),<br>
> -                                    std::move(Resolver)));<br>
> +  /// @brief Add the given module to the lazy emitting layer.<br>
> +  template <typename MemoryManagerPtrT, typename SymbolResolverPtrT><br>
> +  ModuleHandleT addModule(std::shared_ptr<Modu<wbr>le> M,<br>
> +                          MemoryManagerPtrT MemMgr,<br>
> +                          SymbolResolverPtrT Resolver) {<br>
> +    return ModuleList.insert(<br>
> +        ModuleList.end(),<br>
> +        EmissionDeferredModule::create<wbr>(BaseLayer, std::move(M),<br>
> +                                       std::move(MemMgr),<br>
> +                                       std::move(Resolver)));<br>
>    }<br>
><br>
> -  /// @brief Remove the module set represented by the given handle.<br>
> +  /// @brief Remove the module represented by the given handle.<br>
>    ///<br>
> -  ///   This method will free the memory associated with the given module set,<br>
> -  /// both in this layer, and the base layer.<br>
> -  void removeModuleSet(ModuleSetHandl<wbr>eT H) {<br>
> -    (*H)->removeModulesFromBaseLay<wbr>er(BaseLayer);<br>
> -    ModuleSetList.erase(H);<br>
> +  ///   This method will free the memory associated with the given module, both<br>
> +  /// in this layer, and the base layer.<br>
> +  void removeModule(ModuleHandleT H) {<br>
> +    (*H)->removeModuleFromBaseLaye<wbr>r(BaseLayer);<br>
> +    ModuleList.erase(H);<br>
>    }<br>
><br>
>    /// @brief Search for the given named symbol.<br>
> @@ -258,42 +255,40 @@ public:<br>
>      if (auto Symbol = BaseLayer.findSymbol(Name, ExportedSymbolsOnly))<br>
>        return Symbol;<br>
><br>
> -    // If not found then search the deferred sets. If any of these contain a<br>
> +    // If not found then search the deferred modules. If any of these contain a<br>
>      // definition of 'Name' then they will return a JITSymbol that will emit<br>
>      // the corresponding module when the symbol address is requested.<br>
> -    for (auto &DeferredSet : ModuleSetList)<br>
> -      if (auto Symbol = DeferredSet->find(Name, ExportedSymbolsOnly, BaseLayer))<br>
> +    for (auto &DeferredMod : ModuleList)<br>
> +      if (auto Symbol = DeferredMod->find(Name, ExportedSymbolsOnly, BaseLayer))<br>
>          return Symbol;<br>
><br>
>      // If no definition found anywhere return a null symbol.<br>
>      return nullptr;<br>
>    }<br>
><br>
> -  /// @brief Get the address of the given symbol in the context of the set of<br>
> +  /// @brief Get the address of the given symbol in the context of the of<br>
>    ///        compiled modules represented by the handle H.<br>
> -  JITSymbol findSymbolIn(ModuleSetHandleT H, const std::string &Name,<br>
> +  JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name,<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(ModuleSetHandl<wbr>eT H) {<br>
> +  /// @brief Immediately emit and finalize the module represented by the given<br>
> +  ///        handle.<br>
> +  /// @param H Handle for module to emit/finalize.<br>
> +  void emitAndFinalize(ModuleHandleT H) {<br>
>      (*H)->emitAndFinalize(BaseLaye<wbr>r);<br>
>    }<br>
>  };<br>
><br>
>  template <typename BaseLayerT><br>
> -template <typename ModuleSetT, typename MemoryManagerPtrT,<br>
> -          typename SymbolResolverPtrT><br>
> -std::unique_ptr<typename LazyEmittingLayer<BaseLayerT>:<wbr>:EmissionDeferredSet><br>
> -LazyEmittingLayer<BaseLayerT><wbr>::EmissionDeferredSet::create(<br>
> -    BaseLayerT &B, ModuleSetT Ms, MemoryManagerPtrT MemMgr,<br>
> +template <typename MemoryManagerPtrT, typename SymbolResolverPtrT><br>
> +std::unique_ptr<typename LazyEmittingLayer<BaseLayerT>:<wbr>:EmissionDeferredModule><br>
> +LazyEmittingLayer<BaseLayerT><wbr>::EmissionDeferredModule::crea<wbr>te(<br>
> +    BaseLayerT &B, std::shared_ptr<Module> M, MemoryManagerPtrT MemMgr,<br>
>      SymbolResolverPtrT Resolver) {<br>
> -  using EDS = EmissionDeferredSetImpl<Module<wbr>SetT, MemoryManagerPtrT,<br>
> -                                      SymbolResolverPtrT>;<br>
> -  return llvm::make_unique<EDS>(std::mo<wbr>ve(Ms), std::move(MemMgr),<br>
> +  using EDS = EmissionDeferredModuleImpl<Mem<wbr>oryManagerPtrT, SymbolResolverPtrT>;<br>
> +  return llvm::make_unique<EDS>(std::mo<wbr>ve(M), std::move(MemMgr),<br>
>                                  std::move(Resolver));<br>
>  }<br>
><br>
><br>
> Modified: llvm/trunk/lib/ExecutionEngine<wbr>/Orc/OrcCBindings.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/OrcCBindings.cpp?rev=306166&r1=306165&r2=306166&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/lib/Execution<wbr>Engine/Orc/OrcCBindings.cpp?re<wbr>v=306166&r1=306165&r2=306166&<wbr>view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/lib/ExecutionEngine<wbr>/Orc/OrcCBindings.cpp (original)<br>
> +++ llvm/trunk/lib/ExecutionEngine<wbr>/Orc/OrcCBindings.cpp Fri Jun 23 16:45:29 2017<br>
> @@ -12,6 +12,24 @@<br>
><br>
>  using namespace llvm;<br>
><br>
> +LLVMSharedModuleRef LLVMOrcMakeSharedModule(LLVMMo<wbr>duleRef Mod) {<br>
> +  return wrap(new std::shared_ptr<Module>(unwrap<wbr>(Mod)));<br>
> +}<br>
> +<br>
> +void LLVMOrcDisposeSharedModuleRef(<wbr>LLVMSharedModuleRef SharedMod) {<br>
> +  delete unwrap(SharedMod);<br>
> +}<br>
> +<br>
> +LLVMSharedObjectBufferRef<br>
> +LLVMOrcMakeSharedObjectBuffer<wbr>(LLVMMemoryBufferRef ObjBuffer) {<br>
> +  return wrap(new std::shared_ptr<MemoryBuffer>(<wbr>unwrap(ObjBuffer)));<br>
> +}<br>
> +<br>
> +void<br>
> +LLVMOrcDisposeSharedObjectBuf<wbr>ferRef(LLVMSharedObjectBufferR<wbr>ef SharedObjBuffer) {<br>
> +  delete unwrap(SharedObjBuffer);<br>
> +}<br>
> +<br>
>  LLVMOrcJITStackRef LLVMOrcCreateInstance(LLVMTarg<wbr>etMachineRef TM) {<br>
>    TargetMachine *TM2(unwrap(TM));<br>
><br>
> @@ -65,21 +83,23 @@ LLVMOrcErrorCode LLVMOrcSetIndirectStubP<br>
>  }<br>
><br>
>  LLVMOrcModuleHandle<br>
> -LLVMOrcAddEagerlyCompiledIR(L<wbr>LVMOrcJITStackRef JITStack, LLVMModuleRef Mod,<br>
> +LLVMOrcAddEagerlyCompiledIR(L<wbr>LVMOrcJITStackRef JITStack,<br>
> +                            LLVMSharedModuleRef Mod,<br>
>                              LLVMOrcSymbolResolverFn SymbolResolver,<br>
>                              void *SymbolResolverCtx) {<br>
>    OrcCBindingsStack &J = *unwrap(JITStack);<br>
> -  Module *M(unwrap(Mod));<br>
> -  return J.addIRModuleEager(M, SymbolResolver, SymbolResolverCtx);<br>
> +  std::shared_ptr<Module> *M(unwrap(Mod));<br>
> +  return J.addIRModuleEager(*M, SymbolResolver, SymbolResolverCtx);<br>
>  }<br>
><br>
>  LLVMOrcModuleHandle<br>
> -LLVMOrcAddLazilyCompiledIR(LL<wbr>VMOrcJITStackRef JITStack, LLVMModuleRef Mod,<br>
> +LLVMOrcAddLazilyCompiledIR(LL<wbr>VMOrcJITStackRef JITStack,<br>
> +                           LLVMSharedModuleRef Mod,<br>
>                             LLVMOrcSymbolResolverFn SymbolResolver,<br>
>                             void *SymbolResolverCtx) {<br>
>    OrcCBindingsStack &J = *unwrap(JITStack);<br>
> -  Module *M(unwrap(Mod));<br>
> -  return J.addIRModuleLazy(M, SymbolResolver, SymbolResolverCtx);<br>
> +  std::shared_ptr<Module> *M(unwrap(Mod));<br>
> +  return J.addIRModuleLazy(*M, SymbolResolver, SymbolResolverCtx);<br>
>  }<br>
><br>
>  void LLVMOrcRemoveModule(LLVMOrcJIT<wbr>StackRef JITStack, LLVMOrcModuleHandle H) {<br>
><br>
> Modified: llvm/trunk/lib/ExecutionEngine<wbr>/Orc/OrcCBindingsStack.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/OrcCBindingsStack.h?rev=306166&r1=306165&r2=306166&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/lib/Execution<wbr>Engine/Orc/OrcCBindingsStack.h<wbr>?rev=306166&r1=306165&r2=30616<wbr>6&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/lib/ExecutionEngine<wbr>/Orc/OrcCBindingsStack.h (original)<br>
> +++ llvm/trunk/lib/ExecutionEngine<wbr>/Orc/OrcCBindingsStack.h Fri Jun 23 16:45:29 2017<br>
> @@ -42,6 +42,10 @@ namespace llvm {<br>
><br>
>  class OrcCBindingsStack;<br>
><br>
> +DEFINE_SIMPLE_CONVERSION_FUNC<wbr>TIONS(std::shared_ptr<Module>,<br>
> +                                   LLVMSharedModuleRef);<br>
> +DEFINE_SIMPLE_CONVERSION_FUNC<wbr>TIONS(std::shared_ptr<MemoryBu<wbr>ffer>,<br>
> +                                   LLVMSharedObjectBufferRef);<br>
>  DEFINE_SIMPLE_CONVERSION_FUNCT<wbr>IONS(OrcCBindingsStack, LLVMOrcJITStackRef)<br>
>  DEFINE_SIMPLE_CONVERSION_FUNCT<wbr>IONS(TargetMachine, LLVMTargetMachineRef)<br>
><br>
> @@ -71,7 +75,7 @@ private:<br>
><br>
>    template <typename LayerT> class GenericHandleImpl : public GenericHandle {<br>
>    public:<br>
> -    GenericHandleImpl(LayerT &Layer, typename LayerT::ModuleSetHandleT Handle)<br>
> +    GenericHandleImpl(LayerT &Layer, typename LayerT::ModuleHandleT Handle)<br>
>          : Layer(Layer), Handle(std::move(Handle)) {}<br>
><br>
>      JITSymbol findSymbolIn(const std::string &Name,<br>
> @@ -79,24 +83,21 @@ private:<br>
>        return Layer.findSymbolIn(Handle, Name, ExportedSymbolsOnly);<br>
>      }<br>
><br>
> -    void removeModule() override { return Layer.removeModuleSet(Handle); }<br>
> +    void removeModule() override { return Layer.removeModule(Handle); }<br>
><br>
>    private:<br>
>      LayerT &Layer;<br>
> -    typename LayerT::ModuleSetHandleT Handle;<br>
> +    typename LayerT::ModuleHandleT Handle;<br>
>    };<br>
><br>
>    template <typename LayerT><br>
>    std::unique_ptr<GenericHandleI<wbr>mpl<LayerT>><br>
> -  createGenericHandle(LayerT &Layer, typename LayerT::ModuleSetHandleT Handle) {<br>
> +  createGenericHandle(LayerT &Layer, typename LayerT::ModuleHandleT Handle) {<br>
>      return llvm::make_unique<GenericHandl<wbr>eImpl<LayerT>>(Layer,<br>
>                                                          std::move(Handle));<br>
>    }<br>
><br>
>  public:<br>
> -  // We need a 'ModuleSetHandleT' to conform to the layer concept.<br>
> -  using ModuleSetHandleT = unsigned;<br>
> -<br>
>    using ModuleHandleT = unsigned;<br>
><br>
>    OrcCBindingsStack(TargetMachin<wbr>e &TM,<br>
> @@ -183,7 +184,7 @@ public:<br>
>    }<br>
><br>
>    template <typename LayerT><br>
> -  ModuleHandleT addIRModule(LayerT &Layer, Module *M,<br>
> +  ModuleHandleT addIRModule(LayerT &Layer, std::shared_ptr<Module> M,<br>
>                              std::unique_ptr<RuntimeDyld::M<wbr>emoryManager> MemMgr,<br>
>                              LLVMOrcSymbolResolverFn ExternalResolver,<br>
>                              void *ExternalResolverCtx) {<br>
> @@ -203,11 +204,8 @@ public:<br>
>      auto Resolver = createResolver(ExternalResolve<wbr>r, ExternalResolverCtx);<br>
><br>
>      // Add the module to the JIT.<br>
> -    std::vector<Module *> S;<br>
> -    S.push_back(std::move(M));<br>
> -<br>
> -    auto LH = Layer.addModuleSet(std::move(S<wbr>), std::move(MemMgr),<br>
> -                                 std::move(Resolver));<br>
> +    auto LH = Layer.addModule(std::move(M), std::move(MemMgr),<br>
> +                              std::move(Resolver));<br>
>      ModuleHandleT H = createHandle(Layer, LH);<br>
><br>
>      // Run the static constructors, and save the static destructor runner for<br>
> @@ -220,7 +218,7 @@ public:<br>
>      return H;<br>
>    }<br>
><br>
> -  ModuleHandleT addIRModuleEager(Module *M,<br>
> +  ModuleHandleT addIRModuleEager(std::shared_p<wbr>tr<Module> M,<br>
>                                   LLVMOrcSymbolResolverFn ExternalResolver,<br>
>                                   void *ExternalResolverCtx) {<br>
>      return addIRModule(CompileLayer, std::move(M),<br>
> @@ -228,7 +226,7 @@ public:<br>
>                         std::move(ExternalResolver), ExternalResolverCtx);<br>
>    }<br>
><br>
> -  ModuleHandleT addIRModuleLazy(Module *M,<br>
> +  ModuleHandleT addIRModuleLazy(std::shared_pt<wbr>r<Module> M,<br>
>                                  LLVMOrcSymbolResolverFn ExternalResolver,<br>
>                                  void *ExternalResolverCtx) {<br>
>      return addIRModule(CODLayer, std::move(M),<br>
> @@ -257,8 +255,7 @@ public:<br>
><br>
>  private:<br>
>    template <typename LayerT><br>
> -  unsigned createHandle(LayerT &Layer,<br>
> -                        typename LayerT::ModuleSetHandleT Handle) {<br>
> +  unsigned createHandle(LayerT &Layer, typename LayerT::ModuleHandleT Handle) {<br>
>      unsigned NewHandle;<br>
>      if (!FreeHandleIndexes.empty()) {<br>
>        NewHandle = FreeHandleIndexes.back();<br>
><br>
> Modified: llvm/trunk/lib/ExecutionEngine<wbr>/Orc/OrcMCJITReplacement.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h?rev=306166&r1=306165&r2=306166&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/lib/Execution<wbr>Engine/Orc/OrcMCJITReplacement<wbr>.h?rev=306166&r1=306165&r2=306<wbr>166&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/lib/ExecutionEngine<wbr>/Orc/OrcMCJITReplacement.h (original)<br>
> +++ llvm/trunk/lib/ExecutionEngine<wbr>/Orc/OrcMCJITReplacement.h Fri Jun 23 16:45:29 2017<br>
> @@ -191,10 +191,15 @@ public:<br>
>      } else {<br>
>        assert(M->getDataLayout() == getDataLayout() && "DataLayout Mismatch");<br>
>      }<br>
> -    Modules.push_back(std::move(M)<wbr>);<br>
> -    std::vector<Module *> Ms;<br>
> -    Ms.push_back(&*Modules.back())<wbr>;<br>
> -    LazyEmitLayer.addModuleSet(std<wbr>::move(Ms), &MemMgr, &Resolver);<br>
> +    auto *MPtr = M.release();<br>
> +    Retain[MPtr] = false;<br>
> +    auto Deleter =<br>
> +      [this](Module *Mod) {<br>
> +        if (!Retain[Mod])<br>
> +          delete Mod;<br>
> +      };<br>
> +    LocalModules.push_back(std::sh<wbr>ared_ptr<Module>(MPtr, std::move(Deleter)));<br>
> +    LazyEmitLayer.addModule(LocalM<wbr>odules.back(), &MemMgr, &Resolver);<br>
>    }<br>
><br>
>    void addObjectFile(std::unique_ptr<<wbr>object::ObjectFile> O) override {<br>
> @@ -381,6 +386,8 @@ private:<br>
>    std::map<ObjectLayerT::ObjHand<wbr>leT, SectionAddrSet, ObjHandleCompare><br>
>        UnfinalizedSections;<br>
><br>
> +  std::map<Module*, bool> Retain;<br>
> +  std::vector<std::shared_ptr<Mo<wbr>dule>> LocalModules;<br>
>    std::vector<object::OwningBina<wbr>ry<object::Archive>> Archives;<br>
>  };<br>
><br>
><br>
> Modified: llvm/trunk/tools/lli/OrcLazyJI<wbr>T.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lli/OrcLazyJIT.cpp?rev=306166&r1=306165&r2=306166&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/tools/lli/Orc<wbr>LazyJIT.cpp?rev=306166&r1=3061<wbr>65&r2=306166&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/tools/lli/OrcLazyJI<wbr>T.cpp (original)<br>
> +++ llvm/trunk/tools/lli/OrcLazyJI<wbr>T.cpp Fri Jun 23 16:45:29 2017<br>
> @@ -54,10 +54,10 @@ static cl::opt<bool> OrcInlineStubs("orc<br>
>  OrcLazyJIT::TransformFtor OrcLazyJIT::createDebugDumper(<wbr>) {<br>
>    switch (OrcDumpKind) {<br>
>    case DumpKind::NoDump:<br>
> -    return [](std::unique_ptr<Module> M) { return M; };<br>
> +    return [](std::shared_ptr<Module> M) { return M; };<br>
><br>
>    case DumpKind::DumpFuncsToStdOut:<br>
> -    return [](std::unique_ptr<Module> M) {<br>
> +    return [](std::shared_ptr<Module> M) {<br>
>        printf("[ ");<br>
><br>
>        for (const auto &F : *M) {<br>
> @@ -76,7 +76,7 @@ OrcLazyJIT::TransformFtor OrcLazyJIT::cr<br>
>      };<br>
><br>
>    case DumpKind::DumpModsToStdOut:<br>
> -    return [](std::unique_ptr<Module> M) {<br>
> +    return [](std::shared_ptr<Module> M) {<br>
>               outs() << "----- Module Start -----\n" << *M<br>
>                      << "----- Module End -----\n";<br>
><br>
> @@ -84,7 +84,7 @@ OrcLazyJIT::TransformFtor OrcLazyJIT::cr<br>
>             };<br>
><br>
>    case DumpKind::DumpModsToDisk:<br>
> -    return [](std::unique_ptr<Module> M) {<br>
> +    return [](std::shared_ptr<Module> M) {<br>
>               std::error_code EC;<br>
>               raw_fd_ostream Out(M->getModuleIdentifier() + ".ll", EC,<br>
>                                  sys::fs::F_Text);<br>
> @@ -147,7 +147,8 @@ int llvm::runOrcLazyJIT(std::vecto<wbr>r<std:<br>
>                 OrcInlineStubs);<br>
><br>
>    // Add the module, look up main and run it.<br>
> -  J.addModuleSet(std::move(Ms));<br>
> +  for (auto &M : Ms)<br>
> +    J.addModule(std::shared_ptr<Mo<wbr>dule>(std::move(M)));<br>
>    auto MainSym = J.findSymbol("main");<br>
><br>
>    if (!MainSym) {<br>
><br>
> Modified: llvm/trunk/tools/lli/OrcLazyJI<wbr>T.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lli/OrcLazyJIT.h?rev=306166&r1=306165&r2=306166&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/tools/lli/Orc<wbr>LazyJIT.h?rev=306166&r1=306165<wbr>&r2=306166&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/tools/lli/OrcLazyJI<wbr>T.h (original)<br>
> +++ llvm/trunk/tools/lli/OrcLazyJI<wbr>T.h Fri Jun 23 16:45:29 2017<br>
> @@ -50,11 +50,11 @@ public:<br>
>    using ObjLayerT = orc::RTDyldObjectLinkingLayer;<br>
>    using CompileLayerT = orc::IRCompileLayer<ObjLayerT, orc::SimpleCompiler>;<br>
>    using TransformFtor =<br>
> -    std::function<std::unique_ptr<<wbr>Module>(std::unique_ptr<Module<wbr>>)>;<br>
> +          std::function<std::shared_ptr<<wbr>Module>(std::shared_ptr<Module<wbr>>)>;<br>
>    using IRDumpLayerT = orc::IRTransformLayer<CompileL<wbr>ayerT, TransformFtor>;<br>
>    using CODLayerT = orc::CompileOnDemandLayer<IRDu<wbr>mpLayerT, CompileCallbackMgr>;<br>
>    using IndirectStubsManagerBuilder = CODLayerT::IndirectStubsManage<wbr>rBuilderT;<br>
> -  using ModuleSetHandleT = CODLayerT::ModuleSetHandleT;<br>
> +  using ModuleHandleT = CODLayerT::ModuleHandleT;<br>
><br>
>    OrcLazyJIT(std::unique_ptr<Tar<wbr>getMachine> TM,<br>
>               std::unique_ptr<CompileCallba<wbr>ckMgr> CCMgr,<br>
> @@ -77,11 +77,9 @@ public:<br>
>        DtorRunner.runViaLayer(CODLaye<wbr>r);<br>
>    }<br>
><br>
> -  ModuleSetHandleT addModuleSet(std::vector<std::<wbr>unique_ptr<Module>> Ms) {<br>
> -    // Attach a data-layouts if they aren't already present.<br>
> -    for (auto &M : Ms)<br>
> -      if (M->getDataLayout().isDefault(<wbr>))<br>
> -        M->setDataLayout(DL);<br>
> +  void addModule(std::shared_ptr<Modu<wbr>le> M) {<br>
> +    if (M->getDataLayout().isDefault(<wbr>))<br>
> +      M->setDataLayout(DL);<br>
><br>
>      // Rename, bump linkage and record static constructors and destructors.<br>
>      // We have to do this before we hand over ownership of the module to the<br>
> @@ -89,21 +87,19 @@ public:<br>
>      std::vector<std::string> CtorNames, DtorNames;<br>
>      {<br>
>        unsigned CtorId = 0, DtorId = 0;<br>
> -      for (auto &M : Ms) {<br>
> -        for (auto Ctor : orc::getConstructors(*M)) {<br>
> -          std::string NewCtorName = ("$static_ctor." + Twine(CtorId++)).str();<br>
> -          Ctor.Func->setName(NewCtorName<wbr>);<br>
> -          Ctor.Func->setLinkage(GlobalVa<wbr>lue::ExternalLinkage);<br>
> -          Ctor.Func->setVisibility(Globa<wbr>lValue::HiddenVisibility);<br>
> -          CtorNames.push_back(mangle(New<wbr>CtorName));<br>
> -        }<br>
> -        for (auto Dtor : orc::getDestructors(*M)) {<br>
> -          std::string NewDtorName = ("$static_dtor." + Twine(DtorId++)).str();<br>
> -          Dtor.Func->setLinkage(GlobalVa<wbr>lue::ExternalLinkage);<br>
> -          Dtor.Func->setVisibility(Globa<wbr>lValue::HiddenVisibility);<br>
> -          DtorNames.push_back(mangle(Dto<wbr>r.Func->getName()));<br>
> -          Dtor.Func->setName(NewDtorName<wbr>);<br>
> -        }<br>
> +      for (auto Ctor : orc::getConstructors(*M)) {<br>
> +        std::string NewCtorName = ("$static_ctor." + Twine(CtorId++)).str();<br>
> +        Ctor.Func->setName(NewCtorName<wbr>);<br>
> +        Ctor.Func->setLinkage(GlobalVa<wbr>lue::ExternalLinkage);<br>
> +        Ctor.Func->setVisibility(Globa<wbr>lValue::HiddenVisibility);<br>
> +        CtorNames.push_back(mangle(New<wbr>CtorName));<br>
> +      }<br>
> +      for (auto Dtor : orc::getDestructors(*M)) {<br>
> +        std::string NewDtorName = ("$static_dtor." + Twine(DtorId++)).str();<br>
> +        Dtor.Func->setLinkage(GlobalVa<wbr>lue::ExternalLinkage);<br>
> +        Dtor.Func->setVisibility(Globa<wbr>lValue::HiddenVisibility);<br>
> +        DtorNames.push_back(mangle(Dto<wbr>r.Func->getName()));<br>
> +        Dtor.Func->setName(NewDtorName<wbr>);<br>
>        }<br>
>      }<br>
><br>
> @@ -111,41 +107,45 @@ public:<br>
>      //   1) Search the JIT symbols.<br>
>      //   2) Check for C++ runtime overrides.<br>
>      //   3) Search the host process (LLI)'s symbol table.<br>
> -    auto Resolver =<br>
> -      orc::createLambdaResolver(<br>
> -        [this](const std::string &Name) -> JITSymbol {<br>
> -          if (auto Sym = CODLayer.findSymbol(Name, true))<br>
> -            return Sym;<br>
> -          return CXXRuntimeOverrides.searchOver<wbr>rides(Name);<br>
> -        },<br>
> -        [](const std::string &Name) {<br>
> -          if (auto Addr =<br>
> -              RTDyldMemoryManager::getSymbol<wbr>AddressInProcess(Name))<br>
> -            return JITSymbol(Addr, JITSymbolFlags::Exported);<br>
> -          return JITSymbol(nullptr);<br>
> -        }<br>
> -      );<br>
> -<br>
> -    // Add the module to the JIT.<br>
> -    auto H = CODLayer.addModuleSet(std::mov<wbr>e(Ms),<br>
> -                                llvm::make_unique<SectionMemor<wbr>yManager>(),<br>
> -                                std::move(Resolver));<br>
> +    if (ModulesHandle == CODLayerT::ModuleHandleT()) {<br>
> +      auto Resolver =<br>
> +        orc::createLambdaResolver(<br>
> +          [this](const std::string &Name) -> JITSymbol {<br>
> +            if (auto Sym = CODLayer.findSymbol(Name, true))<br>
> +              return Sym;<br>
> +            return CXXRuntimeOverrides.searchOver<wbr>rides(Name);<br>
> +          },<br>
> +          [](const std::string &Name) {<br>
> +            if (auto Addr =<br>
> +                RTDyldMemoryManager::getSymbol<wbr>AddressInProcess(Name))<br>
> +              return JITSymbol(Addr, JITSymbolFlags::Exported);<br>
> +            return JITSymbol(nullptr);<br>
> +          }<br>
> +        );<br>
> +<br>
> +      // Add the module to the JIT.<br>
> +      ModulesHandle =<br>
> +        CODLayer.addModule(std::move(M<wbr>),<br>
> +                           llvm::make_unique<SectionMemo<wbr>ryManager>(),<br>
> +                           std::move(Resolver));<br>
> +    } else<br>
> +      CODLayer.addExtraModule(Module<wbr>sHandle, std::move(M));<br>
><br>
>      // Run the static constructors, and save the static destructor runner for<br>
>      // execution when the JIT is torn down.<br>
> -    orc::CtorDtorRunner<CODLayerT> CtorRunner(std::move(CtorNames<wbr>), H);<br>
> +    orc::CtorDtorRunner<CODLayerT> CtorRunner(std::move(CtorNames<wbr>),<br>
> +                                              ModulesHandle);<br>
>      CtorRunner.runViaLayer(CODLaye<wbr>r);<br>
><br>
> -    IRStaticDestructorRunners.empl<wbr>ace_back(std::move(DtorNames), H);<br>
> -<br>
> -    return H;<br>
> +    IRStaticDestructorRunners.empl<wbr>ace_back(std::move(DtorNames),<br>
> +                                           ModulesHandle);<br>
>    }<br>
><br>
>    JITSymbol findSymbol(const std::string &Name) {<br>
>      return CODLayer.findSymbol(mangle(Nam<wbr>e), true);<br>
>    }<br>
><br>
> -  JITSymbol findSymbolIn(ModuleSetHandleT H, const std::string &Name) {<br>
> +  JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name) {<br>
>      return CODLayer.findSymbolIn(H, mangle(Name), true);<br>
>    }<br>
><br>
> @@ -179,6 +179,7 @@ private:<br>
><br>
>    orc::LocalCXXRuntimeOverrides CXXRuntimeOverrides;<br>
>    std::vector<orc::CtorDtorRunne<wbr>r<CODLayerT>> IRStaticDestructorRunners;<br>
> +  CODLayerT::ModuleHandleT ModulesHandle;<br>
>  };<br>
><br>
>  int runOrcLazyJIT(std::vector<std:<wbr>:unique_ptr<Module>> Ms,<br>
><br>
> Modified: llvm/trunk/unittests/Execution<wbr>Engine/Orc/LazyEmittingLayerTe<wbr>st.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/LazyEmittingLayerTest.cpp?rev=306166&r1=306165&r2=306166&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/unittests/Exe<wbr>cutionEngine/Orc/LazyEmittingL<wbr>ayerTest.cpp?rev=306166&r1=306<wbr>165&r2=306166&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/unittests/Execution<wbr>Engine/Orc/LazyEmittingLayerTe<wbr>st.cpp (original)<br>
> +++ llvm/trunk/unittests/Execution<wbr>Engine/Orc/LazyEmittingLayerTe<wbr>st.cpp Fri Jun 23 16:45:29 2017<br>
> @@ -14,9 +14,9 @@<br>
>  namespace {<br>
><br>
>  struct MockBaseLayer {<br>
> -  typedef int ModuleSetHandleT;<br>
> -  ModuleSetHandleT addModuleSet(<br>
> -                  std::list<std::unique_ptr<llvm<wbr>::Module>>,<br>
> +  typedef int ModuleHandleT;<br>
> +  ModuleHandleT addModule(<br>
> +                  std::shared_ptr<llvm::Module>,<br>
>                    std::unique_ptr<llvm::RuntimeD<wbr>yld::MemoryManager> MemMgr,<br>
>                    std::unique_ptr<llvm::JITSymbo<wbr>lResolver> Resolver) {<br>
>      EXPECT_FALSE(MemMgr);<br>
> @@ -27,7 +27,7 @@ struct MockBaseLayer {<br>
>  TEST(LazyEmittingLayerTest, Empty) {<br>
>    MockBaseLayer M;<br>
>    llvm::orc::LazyEmittingLayer<M<wbr>ockBaseLayer> L(M);<br>
> -  L.addModuleSet(std::list<std::<wbr>unique_ptr<llvm::Module>>(), nullptr, nullptr);<br>
> +  L.addModule(std::unique_ptr<ll<wbr>vm::Module>(), nullptr, nullptr);<br>
>  }<br>
><br>
>  }<br>
><br>
> Modified: llvm/trunk/unittests/Execution<wbr>Engine/Orc/ObjectTransformLaye<wbr>rTest.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/ObjectTransformLayerTest.cpp?rev=306166&r1=306165&r2=306166&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/unittests/Exe<wbr>cutionEngine/Orc/ObjectTransfo<wbr>rmLayerTest.cpp?rev=306166&r1=<wbr>306165&r2=306166&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/unittests/Execution<wbr>Engine/Orc/ObjectTransformLaye<wbr>rTest.cpp (original)<br>
> +++ llvm/trunk/unittests/Execution<wbr>Engine/Orc/ObjectTransformLaye<wbr>rTest.cpp Fri Jun 23 16:45:29 2017<br>
> @@ -314,7 +314,7 @@ TEST(ObjectTransformLayerTest, Main) {<br>
>    // compile.<br>
>    NullResolver Resolver;<br>
>    NullManager Manager;<br>
> -  CompileLayer.addModuleSet(std:<wbr>:vector<llvm::Module *>(), &Manager, &Resolver);<br>
> +  CompileLayer.addModule(std::sh<wbr>ared_ptr<llvm::Module>(), &Manager, &Resolver);<br>
><br>
>    // Make sure that the calls from ObjectTransformLayer to ObjectLinkingLayer<br>
>    // compile.<br>
><br>
> Modified: llvm/trunk/unittests/Execution<wbr>Engine/Orc/OrcCAPITest.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp?rev=306166&r1=306165&r2=306166&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/unittests/Exe<wbr>cutionEngine/Orc/OrcCAPITest.c<wbr>pp?rev=306166&r1=306165&r2=306<wbr>166&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/unittests/Execution<wbr>Engine/Orc/OrcCAPITest.cpp (original)<br>
> +++ llvm/trunk/unittests/Execution<wbr>Engine/Orc/OrcCAPITest.cpp Fri Jun 23 16:45:29 2017<br>
> @@ -65,8 +65,9 @@ protected:<br>
>      CompileContext *CCtx = static_cast<CompileContext*>(C<wbr>tx);<br>
>      auto *ET = CCtx->APIExecTest;<br>
>      CCtx->M = ET->createTestModule(ET->TM->g<wbr>etTargetTriple());<br>
> -    CCtx->H = LLVMOrcAddEagerlyCompiledIR(JI<wbr>TStack, wrap(CCtx->M.get()),<br>
> -                                          myResolver, nullptr);<br>
> +    LLVMSharedModuleRef SM = LLVMOrcMakeSharedModule(wrap(C<wbr>Ctx->M.release()));<br>
> +    CCtx->H = LLVMOrcAddEagerlyCompiledIR(JI<wbr>TStack, SM, myResolver, nullptr);<br>
> +    LLVMOrcDisposeSharedModuleRef(<wbr>SM);<br>
>      CCtx->Compiled = true;<br>
>      LLVMOrcTargetAddress MainAddr = LLVMOrcGetSymbolAddress(JITSta<wbr>ck, "main");<br>
>      LLVMOrcSetIndirectStubPointer(<wbr>JITStack, "foo", MainAddr);<br>
> @@ -87,8 +88,10 @@ TEST_F(OrcCAPIExecutionTest, TestEagerIR<br>
><br>
>    LLVMOrcGetMangledSymbol(JIT, &testFuncName, "testFunc");<br>
><br>
> +  LLVMSharedModuleRef SM = LLVMOrcMakeSharedModule(wrap(M<wbr>.release()));<br>
>    LLVMOrcModuleHandle H =<br>
> -    LLVMOrcAddEagerlyCompiledIR(JI<wbr>T, wrap(M.get()), myResolver, nullptr);<br>
> +    LLVMOrcAddEagerlyCompiledIR(JI<wbr>T, SM, myResolver, nullptr);<br>
> +  LLVMOrcDisposeSharedModuleRef(<wbr>SM);<br>
>    MainFnTy MainFn = (MainFnTy)LLVMOrcGetSymbolAddr<wbr>ess(JIT, "main");<br>
>    int Result = MainFn();<br>
>    EXPECT_EQ(Result, 42)<br>
> @@ -111,8 +114,10 @@ TEST_F(OrcCAPIExecutionTest, TestLazyIRC<br>
><br>
>    LLVMOrcGetMangledSymbol(JIT, &testFuncName, "testFunc");<br>
><br>
> +  LLVMSharedModuleRef SM = LLVMOrcMakeSharedModule(wrap(M<wbr>.release()));<br>
>    LLVMOrcModuleHandle H =<br>
> -    LLVMOrcAddLazilyCompiledIR(JIT<wbr>, wrap(M.get()), myResolver, nullptr);<br>
> +    LLVMOrcAddLazilyCompiledIR(JIT<wbr>, SM, myResolver, nullptr);<br>
> +  LLVMOrcDisposeSharedModuleRef(<wbr>SM);<br>
>    MainFnTy MainFn = (MainFnTy)LLVMOrcGetSymbolAddr<wbr>ess(JIT, "main");<br>
>    int Result = MainFn();<br>
>    EXPECT_EQ(Result, 42)<br>
><br>
> Modified: llvm/trunk/unittests/Execution<wbr>Engine/Orc/OrcTestCommon.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/OrcTestCommon.h?rev=306166&r1=306165&r2=306166&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/unittests/Exe<wbr>cutionEngine/Orc/OrcTestCommon<wbr>.h?rev=306166&r1=306165&r2=306<wbr>166&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/unittests/Execution<wbr>Engine/Orc/OrcTestCommon.h (original)<br>
> +++ llvm/trunk/unittests/Execution<wbr>Engine/Orc/OrcTestCommon.h Fri Jun 23 16:45:29 2017<br>
> @@ -106,65 +106,65 @@ public:<br>
>  };<br>
><br>
>  template <typename HandleT,<br>
> -          typename AddModuleSetFtor,<br>
> -          typename RemoveModuleSetFtor,<br>
> +          typename AddModuleFtor,<br>
> +          typename RemoveModuleFtor,<br>
>            typename FindSymbolFtor,<br>
>            typename FindSymbolInFtor><br>
>  class MockBaseLayer {<br>
>  public:<br>
><br>
> -  typedef HandleT ModuleSetHandleT;<br>
> +  typedef HandleT ModuleHandleT;<br>
><br>
> -  MockBaseLayer(AddModuleSetFtor &&AddModuleSet,<br>
> -                RemoveModuleSetFtor &&RemoveModuleSet,<br>
> +  MockBaseLayer(AddModuleFtor &&AddModule,<br>
> +                RemoveModuleFtor &&RemoveModule,<br>
>                  FindSymbolFtor &&FindSymbol,<br>
>                  FindSymbolInFtor &&FindSymbolIn)<br>
> -      : AddModuleSet(AddModuleSet), RemoveModuleSet(RemoveModuleSe<wbr>t),<br>
> +      : AddModule(AddModule), RemoveModule(RemoveModule),<br>
>          FindSymbol(FindSymbol), FindSymbolIn(FindSymbolIn)<br>
>    {}<br>
><br>
> -  template <typename ModuleSetT, typename MemoryManagerPtrT,<br>
> +  template <typename ModuleT, typename MemoryManagerPtrT,<br>
>              typename SymbolResolverPtrT><br>
> -  ModuleSetHandleT addModuleSet(ModuleSetT Ms, MemoryManagerPtrT MemMgr,<br>
> -                                SymbolResolverPtrT Resolver) {<br>
> -    return AddModuleSet(std::move(Ms), std::move(MemMgr), std::move(Resolver));<br>
> +  ModuleHandleT addModule(ModuleT Ms, MemoryManagerPtrT MemMgr,<br>
> +                          SymbolResolverPtrT Resolver) {<br>
> +    return AddModule(std::move(Ms), std::move(MemMgr), std::move(Resolver));<br>
>    }<br>
><br>
> -  void removeModuleSet(ModuleSetHandl<wbr>eT H) {<br>
> -    RemoveModuleSet(H);<br>
> +  void removeModule(ModuleHandleT H) {<br>
> +    RemoveModule(H);<br>
>    }<br>
><br>
>    JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly) {<br>
>      return FindSymbol(Name, ExportedSymbolsOnly);<br>
>    }<br>
><br>
> -  JITSymbol findSymbolIn(ModuleSetHandleT H, const std::string &Name,<br>
> +  JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name,<br>
>                           bool ExportedSymbolsOnly) {<br>
>      return FindSymbolIn(H, Name, ExportedSymbolsOnly);<br>
>    }<br>
><br>
>  private:<br>
> -  AddModuleSetFtor AddModuleSet;<br>
> -  RemoveModuleSetFtor RemoveModuleSet;<br>
> +  AddModuleFtor AddModule;<br>
> +  RemoveModuleFtor RemoveModule;<br>
>    FindSymbolFtor FindSymbol;<br>
>    FindSymbolInFtor FindSymbolIn;<br>
>  };<br>
><br>
> -template <typename ModuleSetHandleT,<br>
> -          typename AddModuleSetFtor,<br>
> -          typename RemoveModuleSetFtor,<br>
> +template <typename ModuleHandleT,<br>
> +          typename AddModuleFtor,<br>
> +          typename RemoveModuleFtor,<br>
>            typename FindSymbolFtor,<br>
>            typename FindSymbolInFtor><br>
> -MockBaseLayer<ModuleSetHandle<wbr>T, AddModuleSetFtor, RemoveModuleSetFtor,<br>
> +MockBaseLayer<ModuleHandleT, AddModuleFtor, RemoveModuleFtor,<br>
>                FindSymbolFtor, FindSymbolInFtor><br>
> -createMockBaseLayer(AddModule<wbr>SetFtor &&AddModuleSet,<br>
> -                    RemoveModuleSetFtor &&RemoveModuleSet,<br>
> +createMockBaseLayer(AddModule<wbr>Ftor &&AddModule,<br>
> +                    RemoveModuleFtor &&RemoveModule,<br>
>                      FindSymbolFtor &&FindSymbol,<br>
>                      FindSymbolInFtor &&FindSymbolIn) {<br>
> -  return MockBaseLayer<ModuleSetHandleT<wbr>, AddModuleSetFtor, RemoveModuleSetFtor,<br>
> +  return MockBaseLayer<ModuleHandleT, AddModuleFtor, RemoveModuleFtor,<br>
>                         FindSymbolFtor, FindSymbolInFtor>(<br>
> -                         std::forward<AddModuleSetFtor<wbr>>(AddModuleSet),<br>
> -                         std::forward<RemoveModuleSetF<wbr>tor>(RemoveModuleSet),<br>
> +                         std::forward<AddModuleFtor>(A<wbr>ddModule),<br>
> +                         std::forward<RemoveModuleFtor<wbr>>(RemoveModule),<br>
>                           std::forward<FindSymbolFtor>(<wbr>FindSymbol),<br>
>                           std::forward<FindSymbolInFtor<wbr>>(FindSymbolIn));<br>
>  }<br>
><br>
><br>
> ______________________________<wbr>_________________<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/<wbr>mailman/listinfo/llvm-commits</a><br>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>