[llvm] r259549 - [Orc] Turn OrcX86_64::IndirectStubsInfo into a template helper class:

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 2 11:31:16 PST 2016


Author: lhames
Date: Tue Feb  2 13:31:15 2016
New Revision: 259549

URL: http://llvm.org/viewvc/llvm-project?rev=259549&view=rev
Log:
[Orc] Turn OrcX86_64::IndirectStubsInfo into a template helper class:
GenericIndirectStubsInfo.

This will allow architecture support classes for other architectures to re-use
this code.

Modified:
    llvm/trunk/include/llvm/ExecutionEngine/Orc/OrcArchitectureSupport.h
    llvm/trunk/lib/ExecutionEngine/Orc/OrcArchitectureSupport.cpp

Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/OrcArchitectureSupport.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/OrcArchitectureSupport.h?rev=259549&r1=259548&r2=259549&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/OrcArchitectureSupport.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/OrcArchitectureSupport.h Tue Feb  2 13:31:15 2016
@@ -67,6 +67,49 @@ public:
   }
 };
 
+/// @brief Provide information about stub blocks generated by the
+///        makeIndirectStubsBlock function.
+template <unsigned StubSizeVal>
+class GenericIndirectStubsInfo {
+public:
+  const static unsigned StubSize = StubSizeVal;
+
+  GenericIndirectStubsInfo() : NumStubs(0) {}
+  GenericIndirectStubsInfo(unsigned NumStubs, sys::OwningMemoryBlock StubsMem)
+      : NumStubs(NumStubs), StubsMem(std::move(StubsMem)) {}
+  GenericIndirectStubsInfo(GenericIndirectStubsInfo &&Other)
+      : NumStubs(Other.NumStubs), StubsMem(std::move(Other.StubsMem)) {
+    Other.NumStubs = 0;
+  }
+  GenericIndirectStubsInfo &operator=(GenericIndirectStubsInfo &&Other) {
+    NumStubs = Other.NumStubs;
+    Other.NumStubs = 0;
+    StubsMem = std::move(Other.StubsMem);
+    return *this;
+  }
+
+  /// @brief Number of stubs in this block.
+  unsigned getNumStubs() const { return NumStubs; }
+
+  /// @brief Get a pointer to the stub at the given index, which must be in
+  ///        the range 0 .. getNumStubs() - 1.
+  void *getStub(unsigned Idx) const {
+    return static_cast<uint64_t *>(StubsMem.base()) + Idx;
+  }
+
+  /// @brief Get a pointer to the implementation-pointer at the given index,
+  ///        which must be in the range 0 .. getNumStubs() - 1.
+  void **getPtr(unsigned Idx) const {
+    char *PtrsBase =
+      static_cast<char *>(StubsMem.base()) + NumStubs * StubSize;
+    return reinterpret_cast<void **>(PtrsBase) + Idx;
+  }
+
+private:
+  unsigned NumStubs;
+  sys::OwningMemoryBlock StubsMem;
+};
+
 /// @brief X86_64 support.
 ///
 /// X86_64 supports lazy JITing.
@@ -76,6 +119,8 @@ public:
   static const unsigned TrampolineSize = 8;
   static const unsigned ResolverCodeSize = 0x78;
 
+  typedef GenericIndirectStubsInfo<8> IndirectStubsInfo;
+
   typedef TargetAddress (*JITReentryFn)(void *CallbackMgr, void *TrampolineId);
 
   /// @brief Write the resolver code into the given memory. The user is be
@@ -89,48 +134,6 @@ public:
   static void writeTrampolines(uint8_t *TrampolineMem, void *ResolverAddr,
                                unsigned NumTrampolines);
 
-  /// @brief Provide information about stub blocks generated by the
-  ///        makeIndirectStubsBlock function.
-  class IndirectStubsInfo {
-    friend class OrcX86_64;
-
-  public:
-    const static unsigned StubSize = 8;
-
-    IndirectStubsInfo() : NumStubs(0) {}
-    IndirectStubsInfo(IndirectStubsInfo &&Other)
-        : NumStubs(Other.NumStubs), StubsMem(std::move(Other.StubsMem)) {
-      Other.NumStubs = 0;
-    }
-    IndirectStubsInfo &operator=(IndirectStubsInfo &&Other) {
-      NumStubs = Other.NumStubs;
-      Other.NumStubs = 0;
-      StubsMem = std::move(Other.StubsMem);
-      return *this;
-    }
-
-    /// @brief Number of stubs in this block.
-    unsigned getNumStubs() const { return NumStubs; }
-
-    /// @brief Get a pointer to the stub at the given index, which must be in
-    ///        the range 0 .. getNumStubs() - 1.
-    void *getStub(unsigned Idx) const {
-      return static_cast<uint64_t *>(StubsMem.base()) + Idx;
-    }
-
-    /// @brief Get a pointer to the implementation-pointer at the given index,
-    ///        which must be in the range 0 .. getNumStubs() - 1.
-    void **getPtr(unsigned Idx) const {
-      char *PtrsBase =
-          static_cast<char *>(StubsMem.base()) + NumStubs * StubSize;
-      return reinterpret_cast<void **>(PtrsBase) + Idx;
-    }
-
-  private:
-    unsigned NumStubs;
-    sys::OwningMemoryBlock StubsMem;
-  };
-
   /// @brief Emit at least MinStubs worth of indirect call stubs, rounded out to
   ///        the nearest page size.
   ///

Modified: llvm/trunk/lib/ExecutionEngine/Orc/OrcArchitectureSupport.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/OrcArchitectureSupport.cpp?rev=259549&r1=259548&r2=259549&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/OrcArchitectureSupport.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/OrcArchitectureSupport.cpp Tue Feb  2 13:31:15 2016
@@ -161,8 +161,7 @@ std::error_code OrcX86_64::emitIndirectS
   for (unsigned I = 0; I < NumStubs; ++I)
     Ptr[I] = InitialPtrVal;
 
-  StubsInfo.NumStubs = NumStubs;
-  StubsInfo.StubsMem = std::move(StubsMem);
+  StubsInfo = IndirectStubsInfo(NumStubs, std::move(StubsMem));
 
   return std::error_code();
 }




More information about the llvm-commits mailing list