[Orc] Move some code up into the JITCompileCallbackManager base class. NFC.
authorLang Hames <lhames@gmail.com>
Fri, 4 Dec 2015 22:09:19 +0000 (22:09 +0000)
committerLang Hames <lhames@gmail.com>
Fri, 4 Dec 2015 22:09:19 +0000 (22:09 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254778 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ExecutionEngine/Orc/IndirectionUtils.h
unittests/ExecutionEngine/Orc/CompileOnDemandLayerTest.cpp

index b5b258e7a05c9b9ab0f39eb3633b9a13787bc074..3bfff059110cc8b668798351dcaa8f65dab76578 100644 (file)
@@ -84,7 +84,11 @@ public:
   }
 
   /// @brief Reserve a compile callback.
   }
 
   /// @brief Reserve a compile callback.
-  virtual CompileCallbackInfo getCompileCallback() = 0;
+  CompileCallbackInfo getCompileCallback() {
+    TargetAddress TrampolineAddr = getAvailableTrampolineAddr();
+    auto &Compile = this->ActiveTrampolines[TrampolineAddr];
+    return CompileCallbackInfo(TrampolineAddr, Compile);
+  }
 
   /// @brief Get a CompileCallbackInfo for an existing callback.
   CompileCallbackInfo getCompileCallbackInfo(TargetAddress TrampolineAddr) {
 
   /// @brief Get a CompileCallbackInfo for an existing callback.
   CompileCallbackInfo getCompileCallbackInfo(TargetAddress TrampolineAddr) {
@@ -113,6 +117,20 @@ protected:
   std::vector<TargetAddress> AvailableTrampolines;
 
 private:
   std::vector<TargetAddress> AvailableTrampolines;
 
 private:
+
+  TargetAddress getAvailableTrampolineAddr() {
+    if (this->AvailableTrampolines.empty())
+      grow();
+    assert(!this->AvailableTrampolines.empty() &&
+           "Failed to grow available trampolines.");
+    TargetAddress TrampolineAddr = this->AvailableTrampolines.back();
+    this->AvailableTrampolines.pop_back();
+    return TrampolineAddr;
+  }
+
+  // Create new trampolines - to be implemented in subclasses.
+  virtual void grow() = 0;
+
   virtual void anchor();
 };
 
   virtual void anchor();
 };
 
@@ -145,13 +163,6 @@ public:
     assert(!EC && "Failed to mprotect resolver block");
   }
 
     assert(!EC && "Failed to mprotect resolver block");
   }
 
-  /// @brief Get/create a compile callback with the given signature.
-  CompileCallbackInfo getCompileCallback() final {
-    TargetAddress TrampolineAddr = getAvailableTrampolineAddr();
-    auto &Compile = this->ActiveTrampolines[TrampolineAddr];
-    return CompileCallbackInfo(TrampolineAddr, Compile);
-  }
-
 private:
 
   static TargetAddress reenter(void *CCMgr, void *TrampolineId) {
 private:
 
   static TargetAddress reenter(void *CCMgr, void *TrampolineId) {
@@ -162,17 +173,7 @@ private:
                reinterpret_cast<uintptr_t>(TrampolineId)));
   }
 
                reinterpret_cast<uintptr_t>(TrampolineId)));
   }
 
-  TargetAddress getAvailableTrampolineAddr() {
-    if (this->AvailableTrampolines.empty())
-      grow();
-    assert(!this->AvailableTrampolines.empty() &&
-           "Failed to grow available trampolines.");
-    TargetAddress TrampolineAddr = this->AvailableTrampolines.back();
-    this->AvailableTrampolines.pop_back();
-    return TrampolineAddr;
-  }
-
-  void grow() {
+  void grow() override {
     assert(this->AvailableTrampolines.empty() && "Growing prematurely?");
 
     std::error_code EC;
     assert(this->AvailableTrampolines.empty() && "Growing prematurely?");
 
     std::error_code EC;
index 4a30cfc429710c345bdc02cf8632271ad38de2ae..ca508d0a75614d2a3c605fd79786947dd2720e60 100644 (file)
@@ -18,17 +18,9 @@ namespace {
 
 class DummyCallbackManager : public orc::JITCompileCallbackManager {
 public:
 
 class DummyCallbackManager : public orc::JITCompileCallbackManager {
 public:
-  DummyCallbackManager()
-      : JITCompileCallbackManager(0), NextStubAddress(0),
-        UniversalCompile([]() { return 0; }) {
-  }
-
-  CompileCallbackInfo getCompileCallback() override {
-    return CompileCallbackInfo(++NextStubAddress, UniversalCompile);
-  }
+  DummyCallbackManager() : JITCompileCallbackManager(0) { }
 public:
 public:
-  TargetAddress NextStubAddress;
-  CompileFtor UniversalCompile;
+  void grow() override { llvm_unreachable("not implemented"); }
 };
 
 class DummyStubsManager : public orc::IndirectStubsManagerBase {
 };
 
 class DummyStubsManager : public orc::IndirectStubsManagerBase {