[llvm] r295636 - [Orc] Rename ObjectLinkingLayer -> RTDyldObjectLinkingLayer.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 19 21:45:15 PST 2017


Author: lhames
Date: Sun Feb 19 23:45:14 2017
New Revision: 295636

URL: http://llvm.org/viewvc/llvm-project?rev=295636&view=rev
Log:
[Orc] Rename ObjectLinkingLayer -> RTDyldObjectLinkingLayer.

The current ObjectLinkingLayer (now RTDyldObjectLinkingLayer) links objects
in-process using MCJIT's RuntimeDyld class. In the near future I hope to add new
object linking layers (e.g. a remote linking layer that links objects in the JIT
target process, rather than the client), so I'm renaming this class to be more
descriptive.


Added:
    llvm/trunk/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h
      - copied, changed from r295635, llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h
    llvm/trunk/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp
      - copied, changed from r295635, llvm/trunk/unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp
Removed:
    llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h
    llvm/trunk/unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp
Modified:
    llvm/trunk/lib/ExecutionEngine/Orc/OrcCBindingsStack.h
    llvm/trunk/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h
    llvm/trunk/tools/lli/OrcLazyJIT.h
    llvm/trunk/unittests/ExecutionEngine/Orc/CMakeLists.txt
    llvm/trunk/unittests/ExecutionEngine/Orc/ObjectTransformLayerTest.cpp

Removed: llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h?rev=295635&view=auto
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h (removed)
@@ -1,362 +0,0 @@
-//===- ObjectLinkingLayer.h - Add object files to a JIT process -*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// Contains the definition for the object layer of the JIT.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_EXECUTIONENGINE_ORC_OBJECTLINKINGLAYER_H
-#define LLVM_EXECUTIONENGINE_ORC_OBJECTLINKINGLAYER_H
-
-#include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/StringMap.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/ExecutionEngine/ExecutionEngine.h"
-#include "llvm/ExecutionEngine/JITSymbol.h"
-#include "llvm/ExecutionEngine/RuntimeDyld.h"
-#include "llvm/ExecutionEngine/SectionMemoryManager.h"
-#include "llvm/Object/ObjectFile.h"
-#include "llvm/Support/Error.h"
-#include <cassert>
-#include <algorithm>
-#include <functional>
-#include <list>
-#include <memory>
-#include <string>
-#include <utility>
-#include <vector>
-
-namespace llvm {
-namespace orc {
-
-class ObjectLinkingLayerBase {
-protected:
-  /// @brief Holds a set of objects to be allocated/linked as a unit in the JIT.
-  ///
-  /// An instance of this class will be created for each set of objects added
-  /// via JITObjectLayer::addObjectSet. Deleting the instance (via
-  /// removeObjectSet) frees its memory, removing all symbol definitions that
-  /// had been provided by this instance. Higher level layers are responsible
-  /// for taking any action required to handle the missing symbols.
-  class LinkedObjectSet {
-  public:
-    LinkedObjectSet() = default;
-    LinkedObjectSet(const LinkedObjectSet&) = delete;
-    void operator=(const LinkedObjectSet&) = delete;
-    virtual ~LinkedObjectSet() = default;
-
-    virtual void finalize() = 0;
-
-    virtual JITSymbol::GetAddressFtor
-    getSymbolMaterializer(std::string Name) = 0;
-
-    virtual void mapSectionAddress(const void *LocalAddress,
-                                   JITTargetAddress TargetAddr) const = 0;
-
-    JITSymbol getSymbol(StringRef Name, bool ExportedSymbolsOnly) {
-      auto SymEntry = SymbolTable.find(Name);
-      if (SymEntry == SymbolTable.end())
-        return nullptr;
-      if (!SymEntry->second.getFlags().isExported() && ExportedSymbolsOnly)
-        return nullptr;
-      if (!Finalized)
-        return JITSymbol(getSymbolMaterializer(Name),
-                         SymEntry->second.getFlags());
-      return JITSymbol(SymEntry->second);
-    }
-
-  protected:
-    StringMap<JITEvaluatedSymbol> SymbolTable;
-    bool Finalized = false;
-  };
-
-  typedef std::list<std::unique_ptr<LinkedObjectSet>> LinkedObjectSetListT;
-
-public:
-  /// @brief Handle to a set of loaded objects.
-  typedef LinkedObjectSetListT::iterator ObjSetHandleT;
-};
-
-/// @brief Default (no-op) action to perform when loading objects.
-class DoNothingOnNotifyLoaded {
-public:
-  template <typename ObjSetT, typename LoadResult>
-  void operator()(ObjectLinkingLayerBase::ObjSetHandleT, const ObjSetT &,
-                  const LoadResult &) {}
-};
-
-/// @brief Bare bones object linking layer.
-///
-///   This class is intended to be used as the base layer for a JIT. It allows
-/// object files to be loaded into memory, linked, and the addresses of their
-/// symbols queried. All objects added to this layer can see each other's
-/// symbols.
-template <typename NotifyLoadedFtor = DoNothingOnNotifyLoaded>
-class ObjectLinkingLayer : public ObjectLinkingLayerBase {
-public:
-  /// @brief Functor for receiving finalization notifications.
-  typedef std::function<void(ObjSetHandleT)> NotifyFinalizedFtor;
-
-private:
-  template <typename ObjSetT, typename MemoryManagerPtrT,
-            typename SymbolResolverPtrT, typename FinalizerFtor>
-  class ConcreteLinkedObjectSet : public LinkedObjectSet {
-  public:
-    ConcreteLinkedObjectSet(ObjSetT Objects, MemoryManagerPtrT MemMgr,
-                            SymbolResolverPtrT Resolver,
-                            FinalizerFtor Finalizer,
-                            bool ProcessAllSections)
-      : MemMgr(std::move(MemMgr)),
-        PFC(llvm::make_unique<PreFinalizeContents>(std::move(Objects),
-                                                   std::move(Resolver),
-                                                   std::move(Finalizer),
-                                                   ProcessAllSections)) {
-      buildInitialSymbolTable(PFC->Objects);
-    }
-
-    void setHandle(ObjSetHandleT H) {
-      PFC->Handle = H;
-    }
-
-    void finalize() override {
-      assert(PFC && "mapSectionAddress called on finalized LinkedObjectSet");
-
-      RuntimeDyld RTDyld(*MemMgr, *PFC->Resolver);
-      RTDyld.setProcessAllSections(PFC->ProcessAllSections);
-      PFC->RTDyld = &RTDyld;
-
-      this->Finalized = true;
-      PFC->Finalizer(PFC->Handle, RTDyld, std::move(PFC->Objects),
-                     [&]() {
-                       this->updateSymbolTable(RTDyld);
-                     });
-
-      // Release resources.
-      PFC = nullptr;
-    }
-
-    JITSymbol::GetAddressFtor getSymbolMaterializer(std::string Name) override {
-      return
-        [this, Name]() {
-          // The symbol may be materialized between the creation of this lambda
-          // and its execution, so we need to double check.
-          if (!this->Finalized)
-            this->finalize();
-          return this->getSymbol(Name, false).getAddress();
-        };
-    }
-
-    void mapSectionAddress(const void *LocalAddress,
-                           JITTargetAddress TargetAddr) const override {
-      assert(PFC && "mapSectionAddress called on finalized LinkedObjectSet");
-      assert(PFC->RTDyld && "mapSectionAddress called on raw LinkedObjectSet");
-      PFC->RTDyld->mapSectionAddress(LocalAddress, TargetAddr);
-    }
-
-  private:
-    void buildInitialSymbolTable(const ObjSetT &Objects) {
-      for (const auto &Obj : Objects)
-        for (auto &Symbol : getObject(*Obj).symbols()) {
-          if (Symbol.getFlags() & object::SymbolRef::SF_Undefined)
-            continue;
-          Expected<StringRef> SymbolName = Symbol.getName();
-          // FIXME: Raise an error for bad symbols.
-          if (!SymbolName) {
-            consumeError(SymbolName.takeError());
-            continue;
-          }
-          auto Flags = JITSymbolFlags::fromObjectSymbol(Symbol);
-          SymbolTable.insert(
-            std::make_pair(*SymbolName, JITEvaluatedSymbol(0, Flags)));
-        }
-    }
-
-    void updateSymbolTable(const RuntimeDyld &RTDyld) {
-      for (auto &SymEntry : SymbolTable)
-        SymEntry.second = RTDyld.getSymbol(SymEntry.first());
-    }
-
-    // Contains the information needed prior to finalization: the object files,
-    // memory manager, resolver, and flags needed for RuntimeDyld.
-    struct PreFinalizeContents {
-      PreFinalizeContents(ObjSetT Objects, SymbolResolverPtrT Resolver,
-                          FinalizerFtor Finalizer, bool ProcessAllSections)
-        : Objects(std::move(Objects)), Resolver(std::move(Resolver)),
-          Finalizer(std::move(Finalizer)),
-          ProcessAllSections(ProcessAllSections) {}
-
-      ObjSetT Objects;
-      SymbolResolverPtrT Resolver;
-      FinalizerFtor Finalizer;
-      bool ProcessAllSections;
-      ObjSetHandleT Handle;
-      RuntimeDyld *RTDyld;
-    };
-
-    MemoryManagerPtrT MemMgr;
-    std::unique_ptr<PreFinalizeContents> PFC;
-  };
-
-  template <typename ObjSetT, typename MemoryManagerPtrT,
-            typename SymbolResolverPtrT, typename FinalizerFtor>
-  std::unique_ptr<
-    ConcreteLinkedObjectSet<ObjSetT, MemoryManagerPtrT,
-                            SymbolResolverPtrT, FinalizerFtor>>
-  createLinkedObjectSet(ObjSetT Objects, MemoryManagerPtrT MemMgr,
-                        SymbolResolverPtrT Resolver,
-                        FinalizerFtor Finalizer,
-                        bool ProcessAllSections) {
-    typedef ConcreteLinkedObjectSet<ObjSetT, MemoryManagerPtrT,
-                                    SymbolResolverPtrT, FinalizerFtor> LOS;
-    return llvm::make_unique<LOS>(std::move(Objects), std::move(MemMgr),
-                                  std::move(Resolver), std::move(Finalizer),
-                                  ProcessAllSections);
-  }
-
-public:
-  /// @brief LoadedObjectInfo list. Contains a list of owning pointers to
-  ///        RuntimeDyld::LoadedObjectInfo instances.
-  typedef std::vector<std::unique_ptr<RuntimeDyld::LoadedObjectInfo>>
-      LoadedObjInfoList;
-
-  /// @brief Construct an ObjectLinkingLayer with the given NotifyLoaded,
-  ///        and NotifyFinalized functors.
-  ObjectLinkingLayer(
-      NotifyLoadedFtor NotifyLoaded = NotifyLoadedFtor(),
-      NotifyFinalizedFtor NotifyFinalized = NotifyFinalizedFtor())
-      : NotifyLoaded(std::move(NotifyLoaded)),
-        NotifyFinalized(std::move(NotifyFinalized)),
-        ProcessAllSections(false) {}
-
-  /// @brief Set the 'ProcessAllSections' flag.
-  ///
-  /// If set to true, all sections in each object file will be allocated using
-  /// the memory manager, rather than just the sections required for execution.
-  ///
-  /// This is kludgy, and may be removed in the future.
-  void setProcessAllSections(bool ProcessAllSections) {
-    this->ProcessAllSections = ProcessAllSections;
-  }
-
-  /// @brief Add a set of objects (or archives) that will be treated as a unit
-  ///        for the purposes of symbol lookup and memory management.
-  ///
-  /// @return A handle that can be used to refer to the loaded objects (for 
-  ///         symbol searching, finalization, freeing memory, etc.).
-  template <typename ObjSetT,
-            typename MemoryManagerPtrT,
-            typename SymbolResolverPtrT>
-  ObjSetHandleT addObjectSet(ObjSetT Objects,
-                             MemoryManagerPtrT MemMgr,
-                             SymbolResolverPtrT Resolver) {
-    auto Finalizer = [&](ObjSetHandleT H, RuntimeDyld &RTDyld,
-                         const ObjSetT &Objs,
-                         std::function<void()> LOSHandleLoad) {
-      LoadedObjInfoList LoadedObjInfos;
-
-      for (auto &Obj : Objs)
-        LoadedObjInfos.push_back(RTDyld.loadObject(this->getObject(*Obj)));
-
-      LOSHandleLoad();
-
-      this->NotifyLoaded(H, Objs, LoadedObjInfos);
-
-      RTDyld.finalizeWithMemoryManagerLocking();
-
-      if (this->NotifyFinalized)
-        this->NotifyFinalized(H);
-    };
-
-    auto LOS =
-      createLinkedObjectSet(std::move(Objects), std::move(MemMgr),
-                            std::move(Resolver), std::move(Finalizer),
-                            ProcessAllSections);
-    // LOS is an owning-ptr. Keep a non-owning one so that we can set the handle
-    // below.
-    auto *LOSPtr = LOS.get();
-
-    ObjSetHandleT Handle = LinkedObjSetList.insert(LinkedObjSetList.end(),
-                                                   std::move(LOS));
-    LOSPtr->setHandle(Handle);
-
-    return Handle;
-  }
-
-  /// @brief Remove the set of objects associated with handle H.
-  ///
-  ///   All memory allocated for the objects will be freed, and the sections and
-  /// symbols they provided will no longer be available. No attempt is made to
-  /// re-emit the missing symbols, and any use of these symbols (directly or
-  /// indirectly) will result in undefined behavior. If dependence tracking is
-  /// required to detect or resolve such issues it should be added at a higher
-  /// layer.
-  void removeObjectSet(ObjSetHandleT H) {
-    // How do we invalidate the symbols in H?
-    LinkedObjSetList.erase(H);
-  }
-
-  /// @brief Search for the given named symbol.
-  /// @param Name The name of the symbol to search for.
-  /// @param ExportedSymbolsOnly If true, search only for exported symbols.
-  /// @return A handle for the given named symbol, if it exists.
-  JITSymbol findSymbol(StringRef Name, bool ExportedSymbolsOnly) {
-    for (auto I = LinkedObjSetList.begin(), E = LinkedObjSetList.end(); I != E;
-         ++I)
-      if (auto Symbol = findSymbolIn(I, Name, ExportedSymbolsOnly))
-        return Symbol;
-
-    return nullptr;
-  }
-
-  /// @brief Search for the given named symbol in the context of the set of
-  ///        loaded objects represented by the handle H.
-  /// @param H The handle for the object set to search in.
-  /// @param Name The name of the symbol to search for.
-  /// @param ExportedSymbolsOnly If true, search only for exported symbols.
-  /// @return A handle for the given named symbol, if it is found in the
-  ///         given object set.
-  JITSymbol findSymbolIn(ObjSetHandleT H, StringRef Name,
-                         bool ExportedSymbolsOnly) {
-    return (*H)->getSymbol(Name, ExportedSymbolsOnly);
-  }
-
-  /// @brief Map section addresses for the objects associated with the handle H.
-  void mapSectionAddress(ObjSetHandleT H, const void *LocalAddress,
-                         JITTargetAddress TargetAddr) {
-    (*H)->mapSectionAddress(LocalAddress, TargetAddr);
-  }
-
-  /// @brief Immediately emit and finalize the object set represented by the
-  ///        given handle.
-  /// @param H Handle for object set to emit/finalize.
-  void emitAndFinalize(ObjSetHandleT H) {
-    (*H)->finalize();
-  }
-
-private:
-  static const object::ObjectFile& getObject(const object::ObjectFile &Obj) {
-    return Obj;
-  }
-
-  template <typename ObjT>
-  static const object::ObjectFile&
-  getObject(const object::OwningBinary<ObjT> &Obj) {
-    return *Obj.getBinary();
-  }
-
-  LinkedObjectSetListT LinkedObjSetList;
-  NotifyLoadedFtor NotifyLoaded;
-  NotifyFinalizedFtor NotifyFinalized;
-  bool ProcessAllSections;
-};
-
-} // end namespace orc
-} // end namespace llvm
-
-#endif // LLVM_EXECUTIONENGINE_ORC_OBJECTLINKINGLAYER_H

Copied: llvm/trunk/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h (from r295635, llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h?p2=llvm/trunk/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h&p1=llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h&r1=295635&r2=295636&rev=295636&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h Sun Feb 19 23:45:14 2017
@@ -1,4 +1,4 @@
-//===- ObjectLinkingLayer.h - Add object files to a JIT process -*- C++ -*-===//
+//===-- RTDyldObjectLinkingLayer.h - RTDyld-based jit linking  --*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -7,12 +7,12 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// Contains the definition for the object layer of the JIT.
+// Contains the definition for an RTDyld-based, in-process object linking layer.
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_EXECUTIONENGINE_ORC_OBJECTLINKINGLAYER_H
-#define LLVM_EXECUTIONENGINE_ORC_OBJECTLINKINGLAYER_H
+#ifndef LLVM_EXECUTIONENGINE_ORC_RTDYLDOBJECTLINKINGLAYER_H
+#define LLVM_EXECUTIONENGINE_ORC_RTDYLDOBJECTLINKINGLAYER_H
 
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringMap.h"
@@ -35,7 +35,7 @@
 namespace llvm {
 namespace orc {
 
-class ObjectLinkingLayerBase {
+class RTDyldObjectLinkingLayerBase {
 protected:
   /// @brief Holds a set of objects to be allocated/linked as a unit in the JIT.
   ///
@@ -87,7 +87,7 @@ public:
 class DoNothingOnNotifyLoaded {
 public:
   template <typename ObjSetT, typename LoadResult>
-  void operator()(ObjectLinkingLayerBase::ObjSetHandleT, const ObjSetT &,
+  void operator()(RTDyldObjectLinkingLayerBase::ObjSetHandleT, const ObjSetT &,
                   const LoadResult &) {}
 };
 
@@ -98,7 +98,7 @@ public:
 /// symbols queried. All objects added to this layer can see each other's
 /// symbols.
 template <typename NotifyLoadedFtor = DoNothingOnNotifyLoaded>
-class ObjectLinkingLayer : public ObjectLinkingLayerBase {
+class RTDyldObjectLinkingLayer : public RTDyldObjectLinkingLayerBase {
 public:
   /// @brief Functor for receiving finalization notifications.
   typedef std::function<void(ObjSetHandleT)> NotifyFinalizedFtor;
@@ -227,7 +227,7 @@ public:
 
   /// @brief Construct an ObjectLinkingLayer with the given NotifyLoaded,
   ///        and NotifyFinalized functors.
-  ObjectLinkingLayer(
+  RTDyldObjectLinkingLayer(
       NotifyLoadedFtor NotifyLoaded = NotifyLoadedFtor(),
       NotifyFinalizedFtor NotifyFinalized = NotifyFinalizedFtor())
       : NotifyLoaded(std::move(NotifyLoaded)),
@@ -359,4 +359,4 @@ private:
 } // end namespace orc
 } // end namespace llvm
 
-#endif // LLVM_EXECUTIONENGINE_ORC_OBJECTLINKINGLAYER_H
+#endif // LLVM_EXECUTIONENGINE_ORC_RTDYLDOBJECTLINKINGLAYER_H

Modified: llvm/trunk/lib/ExecutionEngine/Orc/OrcCBindingsStack.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/OrcCBindingsStack.h?rev=295636&r1=295635&r2=295636&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/OrcCBindingsStack.h (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/OrcCBindingsStack.h Sun Feb 19 23:45:14 2017
@@ -16,7 +16,7 @@
 #include "llvm/ExecutionEngine/Orc/CompileUtils.h"
 #include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
 #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
-#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
+#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/Support/Error.h"
 
@@ -30,7 +30,7 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Targe
 class OrcCBindingsStack {
 public:
   typedef orc::JITCompileCallbackManager CompileCallbackMgr;
-  typedef orc::ObjectLinkingLayer<> ObjLayerT;
+  typedef orc::RTDyldObjectLinkingLayer<> ObjLayerT;
   typedef orc::IRCompileLayer<ObjLayerT> CompileLayerT;
   typedef orc::CompileOnDemandLayer<CompileLayerT, CompileCallbackMgr>
       CODLayerT;

Modified: llvm/trunk/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h?rev=295636&r1=295635&r2=295636&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h Sun Feb 19 23:45:14 2017
@@ -24,7 +24,7 @@
 #include "llvm/ExecutionEngine/Orc/CompileUtils.h"
 #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
 #include "llvm/ExecutionEngine/Orc/LazyEmittingLayer.h"
-#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
+#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/Mangler.h"
 #include "llvm/Object/Archive.h"
@@ -315,7 +315,7 @@ private:
     NotifyObjectLoadedT(OrcMCJITReplacement &M) : M(M) {}
 
     template <typename ObjListT>
-    void operator()(ObjectLinkingLayerBase::ObjSetHandleT H,
+    void operator()(RTDyldObjectLinkingLayerBase::ObjSetHandleT H,
                     const ObjListT &Objects,
                     const LoadedObjInfoListT &Infos) const {
       M.UnfinalizedSections[H] = std::move(M.SectionsAllocatedSinceLastLoad);
@@ -344,7 +344,7 @@ private:
   public:
     NotifyFinalizedT(OrcMCJITReplacement &M) : M(M) {}
 
-    void operator()(ObjectLinkingLayerBase::ObjSetHandleT H) {
+    void operator()(RTDyldObjectLinkingLayerBase::ObjSetHandleT H) {
       M.UnfinalizedSections.erase(H);
     }
 
@@ -361,7 +361,7 @@ private:
     return MangledName;
   }
 
-  typedef ObjectLinkingLayer<NotifyObjectLoadedT> ObjectLayerT;
+  typedef RTDyldObjectLinkingLayer<NotifyObjectLoadedT> ObjectLayerT;
   typedef IRCompileLayer<ObjectLayerT> CompileLayerT;
   typedef LazyEmittingLayer<CompileLayerT> LazyEmitLayerT;
 

Modified: llvm/trunk/tools/lli/OrcLazyJIT.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lli/OrcLazyJIT.h?rev=295636&r1=295635&r2=295636&view=diff
==============================================================================
--- llvm/trunk/tools/lli/OrcLazyJIT.h (original)
+++ llvm/trunk/tools/lli/OrcLazyJIT.h Sun Feb 19 23:45:14 2017
@@ -21,7 +21,7 @@
 #include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
 #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
 #include "llvm/ExecutionEngine/Orc/IRTransformLayer.h"
-#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
+#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
 #include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
 
 namespace llvm {
@@ -30,7 +30,7 @@ class OrcLazyJIT {
 public:
 
   typedef orc::JITCompileCallbackManager CompileCallbackMgr;
-  typedef orc::ObjectLinkingLayer<> ObjLayerT;
+  typedef orc::RTDyldObjectLinkingLayer<> ObjLayerT;
   typedef orc::IRCompileLayer<ObjLayerT> CompileLayerT;
   typedef std::function<std::unique_ptr<Module>(std::unique_ptr<Module>)>
     TransformFtor;

Modified: llvm/trunk/unittests/ExecutionEngine/Orc/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/CMakeLists.txt?rev=295636&r1=295635&r2=295636&view=diff
==============================================================================
--- llvm/trunk/unittests/ExecutionEngine/Orc/CMakeLists.txt (original)
+++ llvm/trunk/unittests/ExecutionEngine/Orc/CMakeLists.txt Sun Feb 19 23:45:14 2017
@@ -14,7 +14,7 @@ add_llvm_unittest(OrcJITTests
   IndirectionUtilsTest.cpp
   GlobalMappingLayerTest.cpp
   LazyEmittingLayerTest.cpp
-  ObjectLinkingLayerTest.cpp
+  RTDyldObjectLinkingLayerTest.cpp
   ObjectTransformLayerTest.cpp
   OrcCAPITest.cpp
   OrcTestCommon.cpp

Removed: llvm/trunk/unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp?rev=295635&view=auto
==============================================================================
--- llvm/trunk/unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp (original)
+++ llvm/trunk/unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp (removed)
@@ -1,247 +0,0 @@
-//===-- ObjectLinkingLayerTest.cpp - Unit tests for object linking layer --===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "OrcTestCommon.h"
-#include "llvm/ExecutionEngine/ExecutionEngine.h"
-#include "llvm/ExecutionEngine/SectionMemoryManager.h"
-#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
-#include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
-#include "llvm/ExecutionEngine/Orc/NullResolver.h"
-#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
-#include "llvm/IR/Constants.h"
-#include "llvm/IR/LLVMContext.h"
-#include "gtest/gtest.h"
-
-using namespace llvm;
-using namespace llvm::orc;
-
-namespace {
-
-class ObjectLinkingLayerExecutionTest : public testing::Test,
-                                        public OrcExecutionTest {
-
-};
-
-class SectionMemoryManagerWrapper : public SectionMemoryManager {
-public:
-  int FinalizationCount = 0;
-  int NeedsToReserveAllocationSpaceCount = 0;
-
-  bool needsToReserveAllocationSpace() override {
-    ++NeedsToReserveAllocationSpaceCount;
-    return SectionMemoryManager::needsToReserveAllocationSpace();
-  }
-
-  bool finalizeMemory(std::string *ErrMsg = nullptr) override {
-    ++FinalizationCount;
-    return SectionMemoryManager::finalizeMemory(ErrMsg);
-  }
-};
-
-TEST(ObjectLinkingLayerTest, TestSetProcessAllSections) {
-  class SectionMemoryManagerWrapper : public SectionMemoryManager {
-  public:
-    SectionMemoryManagerWrapper(bool &DebugSeen) : DebugSeen(DebugSeen) {}
-    uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
-                                 unsigned SectionID,
-                                 StringRef SectionName,
-                                 bool IsReadOnly) override {
-      if (SectionName == ".debug_str")
-        DebugSeen = true;
-      return SectionMemoryManager::allocateDataSection(Size, Alignment,
-                                                         SectionID,
-                                                         SectionName,
-                                                         IsReadOnly);
-    }
-  private:
-    bool DebugSeen;
-  };
-
-  ObjectLinkingLayer<> ObjLayer;
-
-  LLVMContext Context;
-  auto M = llvm::make_unique<Module>("", Context);
-  M->setTargetTriple("x86_64-unknown-linux-gnu");
-  Type *Int32Ty = IntegerType::get(Context, 32);
-  GlobalVariable *GV =
-    new GlobalVariable(*M, Int32Ty, false, GlobalValue::ExternalLinkage,
-                         ConstantInt::get(Int32Ty, 42), "foo");
-
-  GV->setSection(".debug_str");
-
-  std::unique_ptr<TargetMachine> TM(
-    EngineBuilder().selectTarget(Triple(M->getTargetTriple()), "", "",
-                                 SmallVector<std::string, 1>()));
-  if (!TM)
-    return;
-
-  auto OwningObj = SimpleCompiler(*TM)(*M);
-  std::vector<object::ObjectFile*> Objs;
-  Objs.push_back(OwningObj.getBinary());
-
-  bool DebugSectionSeen = false;
-  SectionMemoryManagerWrapper SMMW(DebugSectionSeen);
-  auto Resolver =
-    createLambdaResolver(
-      [](const std::string &Name) {
-        return JITSymbol(nullptr);
-      },
-      [](const std::string &Name) {
-        return JITSymbol(nullptr);
-      });
-
-  {
-    // Test with ProcessAllSections = false (the default).
-    auto H = ObjLayer.addObjectSet(Objs, &SMMW, &*Resolver);
-    EXPECT_EQ(DebugSectionSeen, false)
-      << "Unexpected debug info section";
-    ObjLayer.removeObjectSet(H);
-  }
-
-  {
-    // Test with ProcessAllSections = true.
-    ObjLayer.setProcessAllSections(true);
-    auto H = ObjLayer.addObjectSet(Objs, &SMMW, &*Resolver);
-    EXPECT_EQ(DebugSectionSeen, true)
-      << "Expected debug info section not seen";
-    ObjLayer.removeObjectSet(H);
-  }
-}
-
-TEST_F(ObjectLinkingLayerExecutionTest, NoDuplicateFinalization) {
-  if (!TM)
-    return;
-
-  ObjectLinkingLayer<> ObjLayer;
-  SimpleCompiler Compile(*TM);
-
-  // Create a pair of modules that will trigger recursive finalization:
-  // Module 1:
-  //   int bar() { return 42; }
-  // Module 2:
-  //   int bar();
-  //   int foo() { return bar(); }
-  //
-  // Verify that the memory manager is only finalized once (for Module 2).
-  // Failure suggests that finalize is being called on the inner RTDyld
-  // instance (for Module 1) which is unsafe, as it will prevent relocation of
-  // Module 2.
-
-  ModuleBuilder MB1(Context, "", "dummy");
-  {
-    MB1.getModule()->setDataLayout(TM->createDataLayout());
-    Function *BarImpl = MB1.createFunctionDecl<int32_t(void)>("bar");
-    BasicBlock *BarEntry = BasicBlock::Create(Context, "entry", BarImpl);
-    IRBuilder<> Builder(BarEntry);
-    IntegerType *Int32Ty = IntegerType::get(Context, 32);
-    Value *FourtyTwo = ConstantInt::getSigned(Int32Ty, 42);
-    Builder.CreateRet(FourtyTwo);
-  }
-
-  auto Obj1 = Compile(*MB1.getModule());
-  std::vector<object::ObjectFile*> Obj1Set;
-  Obj1Set.push_back(Obj1.getBinary());
-
-  ModuleBuilder MB2(Context, "", "dummy");
-  {
-    MB2.getModule()->setDataLayout(TM->createDataLayout());
-    Function *BarDecl = MB2.createFunctionDecl<int32_t(void)>("bar");
-    Function *FooImpl = MB2.createFunctionDecl<int32_t(void)>("foo");
-    BasicBlock *FooEntry = BasicBlock::Create(Context, "entry", FooImpl);
-    IRBuilder<> Builder(FooEntry);
-    Builder.CreateRet(Builder.CreateCall(BarDecl));
-  }
-  auto Obj2 = Compile(*MB2.getModule());
-  std::vector<object::ObjectFile*> Obj2Set;
-  Obj2Set.push_back(Obj2.getBinary());
-
-  auto Resolver =
-    createLambdaResolver(
-      [&](const std::string &Name) {
-        if (auto Sym = ObjLayer.findSymbol(Name, true))
-          return Sym;
-        return JITSymbol(nullptr);
-      },
-      [](const std::string &Name) {
-        return JITSymbol(nullptr);
-      });
-
-  SectionMemoryManagerWrapper SMMW;
-  ObjLayer.addObjectSet(std::move(Obj1Set), &SMMW, &*Resolver);
-  auto H = ObjLayer.addObjectSet(std::move(Obj2Set), &SMMW, &*Resolver);
-  ObjLayer.emitAndFinalize(H);
-
-  // Finalization of module 2 should trigger finalization of module 1.
-  // Verify that finalize on SMMW is only called once.
-  EXPECT_EQ(SMMW.FinalizationCount, 1)
-      << "Extra call to finalize";
-}
-
-TEST_F(ObjectLinkingLayerExecutionTest, NoPrematureAllocation) {
-  if (!TM)
-    return;
-
-  ObjectLinkingLayer<> ObjLayer;
-  SimpleCompiler Compile(*TM);
-
-  // Create a pair of unrelated modules:
-  //
-  // Module 1:
-  //   int foo() { return 42; }
-  // Module 2:
-  //   int bar() { return 7; }
-  //
-  // Both modules will share a memory manager. We want to verify that the
-  // second object is not loaded before the first one is finalized. To do this
-  // in a portable way, we abuse the
-  // RuntimeDyld::MemoryManager::needsToReserveAllocationSpace hook, which is
-  // called once per object before any sections are allocated.
-
-  ModuleBuilder MB1(Context, "", "dummy");
-  {
-    MB1.getModule()->setDataLayout(TM->createDataLayout());
-    Function *BarImpl = MB1.createFunctionDecl<int32_t(void)>("foo");
-    BasicBlock *BarEntry = BasicBlock::Create(Context, "entry", BarImpl);
-    IRBuilder<> Builder(BarEntry);
-    IntegerType *Int32Ty = IntegerType::get(Context, 32);
-    Value *FourtyTwo = ConstantInt::getSigned(Int32Ty, 42);
-    Builder.CreateRet(FourtyTwo);
-  }
-
-  auto Obj1 = Compile(*MB1.getModule());
-  std::vector<object::ObjectFile*> Obj1Set;
-  Obj1Set.push_back(Obj1.getBinary());
-
-  ModuleBuilder MB2(Context, "", "dummy");
-  {
-    MB2.getModule()->setDataLayout(TM->createDataLayout());
-    Function *BarImpl = MB2.createFunctionDecl<int32_t(void)>("bar");
-    BasicBlock *BarEntry = BasicBlock::Create(Context, "entry", BarImpl);
-    IRBuilder<> Builder(BarEntry);
-    IntegerType *Int32Ty = IntegerType::get(Context, 32);
-    Value *Seven = ConstantInt::getSigned(Int32Ty, 7);
-    Builder.CreateRet(Seven);
-  }
-  auto Obj2 = Compile(*MB2.getModule());
-  std::vector<object::ObjectFile*> Obj2Set;
-  Obj2Set.push_back(Obj2.getBinary());
-
-  SectionMemoryManagerWrapper SMMW;
-  NullResolver NR;
-  auto H = ObjLayer.addObjectSet(std::move(Obj1Set), &SMMW, &NR);
-  ObjLayer.addObjectSet(std::move(Obj2Set), &SMMW, &NR);
-  ObjLayer.emitAndFinalize(H);
-
-  // Only one call to needsToReserveAllocationSpace should have been made.
-  EXPECT_EQ(SMMW.NeedsToReserveAllocationSpaceCount, 1)
-      << "More than one call to needsToReserveAllocationSpace "
-         "(multiple unrelated objects loaded prior to finalization)";
-}
-
-} // end anonymous namespace

Modified: llvm/trunk/unittests/ExecutionEngine/Orc/ObjectTransformLayerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/ObjectTransformLayerTest.cpp?rev=295636&r1=295635&r2=295636&view=diff
==============================================================================
--- llvm/trunk/unittests/ExecutionEngine/Orc/ObjectTransformLayerTest.cpp (original)
+++ llvm/trunk/unittests/ExecutionEngine/Orc/ObjectTransformLayerTest.cpp Sun Feb 19 23:45:14 2017
@@ -12,7 +12,7 @@
 #include "llvm/ExecutionEngine/Orc/CompileUtils.h"
 #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
 #include "llvm/ExecutionEngine/Orc/NullResolver.h"
-#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
+#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
 #include "llvm/ExecutionEngine/Orc/ObjectTransformLayer.h"
 #include "llvm/Object/ObjectFile.h"
 #include "gtest/gtest.h"
@@ -309,7 +309,7 @@ TEST(ObjectTransformLayerTest, Main) {
   };
 
   // Construct the jit layers.
-  ObjectLinkingLayer<> BaseLayer;
+  RTDyldObjectLinkingLayer<> BaseLayer;
   auto IdentityTransform = [](
       std::unique_ptr<llvm::object::OwningBinary<llvm::object::ObjectFile>>
           Obj) { return Obj; };

Copied: llvm/trunk/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp (from r295635, llvm/trunk/unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp?p2=llvm/trunk/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp&p1=llvm/trunk/unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp&r1=295635&r2=295636&rev=295636&view=diff
==============================================================================
--- llvm/trunk/unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp (original)
+++ llvm/trunk/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp Sun Feb 19 23:45:14 2017
@@ -1,4 +1,4 @@
-//===-- ObjectLinkingLayerTest.cpp - Unit tests for object linking layer --===//
+//===- RTDyldObjectLinkingLayerTest.cpp - RTDyld linking layer unit tests -===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -13,7 +13,7 @@
 #include "llvm/ExecutionEngine/Orc/CompileUtils.h"
 #include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
 #include "llvm/ExecutionEngine/Orc/NullResolver.h"
-#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
+#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/LLVMContext.h"
 #include "gtest/gtest.h"
@@ -23,8 +23,8 @@ using namespace llvm::orc;
 
 namespace {
 
-class ObjectLinkingLayerExecutionTest : public testing::Test,
-                                        public OrcExecutionTest {
+class RTDyldObjectLinkingLayerExecutionTest : public testing::Test,
+                                              public OrcExecutionTest {
 
 };
 
@@ -44,7 +44,7 @@ public:
   }
 };
 
-TEST(ObjectLinkingLayerTest, TestSetProcessAllSections) {
+TEST(RTDyldObjectLinkingLayerTest, TestSetProcessAllSections) {
   class SectionMemoryManagerWrapper : public SectionMemoryManager {
   public:
     SectionMemoryManagerWrapper(bool &DebugSeen) : DebugSeen(DebugSeen) {}
@@ -63,7 +63,7 @@ TEST(ObjectLinkingLayerTest, TestSetProc
     bool DebugSeen;
   };
 
-  ObjectLinkingLayer<> ObjLayer;
+  RTDyldObjectLinkingLayer<> ObjLayer;
 
   LLVMContext Context;
   auto M = llvm::make_unique<Module>("", Context);
@@ -114,11 +114,11 @@ TEST(ObjectLinkingLayerTest, TestSetProc
   }
 }
 
-TEST_F(ObjectLinkingLayerExecutionTest, NoDuplicateFinalization) {
+TEST_F(RTDyldObjectLinkingLayerExecutionTest, NoDuplicateFinalization) {
   if (!TM)
     return;
 
-  ObjectLinkingLayer<> ObjLayer;
+  RTDyldObjectLinkingLayer<> ObjLayer;
   SimpleCompiler Compile(*TM);
 
   // Create a pair of modules that will trigger recursive finalization:
@@ -183,11 +183,11 @@ TEST_F(ObjectLinkingLayerExecutionTest,
       << "Extra call to finalize";
 }
 
-TEST_F(ObjectLinkingLayerExecutionTest, NoPrematureAllocation) {
+TEST_F(RTDyldObjectLinkingLayerExecutionTest, NoPrematureAllocation) {
   if (!TM)
     return;
 
-  ObjectLinkingLayer<> ObjLayer;
+  RTDyldObjectLinkingLayer<> ObjLayer;
   SimpleCompiler Compile(*TM);
 
   // Create a pair of unrelated modules:




More information about the llvm-commits mailing list