[ORC] Use EPC for EPCGeneric MemoryAccess / JITLinkMemoryManager construction.
authorLang Hames <lhames@gmail.com>
Sun, 5 Sep 2021 08:29:05 +0000 (18:29 +1000)
committerLang Hames <lhames@gmail.com>
Sat, 11 Sep 2021 01:24:00 +0000 (11:24 +1000)
This allows these classes to be created during EPC construction, before an
ExecutionSession is available.

llvm/include/llvm/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.h
llvm/include/llvm/ExecutionEngine/Orc/EPCGenericMemoryAccess.h
llvm/lib/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.cpp
llvm/lib/ExecutionEngine/Orc/EPCGenericMemoryAccess.cpp

index 6ad2351..0dd1e6a 100644 (file)
@@ -38,10 +38,10 @@ public:
   EPCGenericJITLinkMemoryManager(ExecutorProcessControl &EPC, FuncAddrs FAs)
       : EPC(EPC), FAs(FAs) {}
 
-  /// Create using the standard memory access function names from the ORC
-  /// runtime.
+  /// Create using the standard memory allocation function names from the
+  /// ORCTargetProcess library.
   static Expected<std::unique_ptr<EPCGenericJITLinkMemoryManager>>
-  CreateUsingOrcRTFuncs(ExecutionSession &ES, JITDylib &OrcRuntimeJD);
+  CreateUsingOrcRTFuncs(ExecutorProcessControl &EPC);
 
   Expected<std::unique_ptr<Allocation>>
   allocate(const jitlink::JITLinkDylib *JD,
index 20a4784..fe9d1c1 100644 (file)
@@ -39,10 +39,10 @@ public:
   EPCGenericMemoryAccess(ExecutorProcessControl &EPC, FuncAddrs FAs)
       : EPC(EPC), FAs(FAs) {}
 
-  /// Create using the standard memory access function names from the ORC
-  /// runtime.
+  /// Create using the standard memory access function names from the
+  /// ORCTargetProcess library.
   static Expected<std::unique_ptr<EPCGenericMemoryAccess>>
-  CreateUsingOrcRTFuncs(ExecutionSession &ES, JITDylib &OrcRuntimeJD);
+  CreateUsingOrcRTFuncs(ExecutorProcessControl &EPC);
 
   void writeUInt8sAsync(ArrayRef<tpctypes::UInt8Write> Ws,
                         WriteResultFn OnWriteComplete) override {
index 012ff73..ac6de22 100644 (file)
@@ -88,25 +88,28 @@ private:
 
 /// Create from a ExecutorProcessControl instance.
 Expected<std::unique_ptr<EPCGenericJITLinkMemoryManager>>
-EPCGenericJITLinkMemoryManager::CreateUsingOrcRTFuncs(ExecutionSession &ES,
-                                                      JITDylib &OrcRuntimeJD) {
+EPCGenericJITLinkMemoryManager::CreateUsingOrcRTFuncs(
+    ExecutorProcessControl &EPC) {
+
+  auto H = EPC.loadDylib("");
+  if (!H)
+    return H.takeError();
 
   StringRef GlobalPrefix = "";
-  if (ES.getExecutorProcessControl().getTargetTriple().isOSBinFormatMachO())
+  if (EPC.getTargetTriple().isOSBinFormatMachO())
     GlobalPrefix = "_";
 
   FuncAddrs FAs;
   if (auto Err = lookupAndRecordAddrs(
-          ES, LookupKind::Static, makeJITDylibSearchOrder(&OrcRuntimeJD),
-          {{ES.intern((GlobalPrefix + "__orc_rt_reserve").str()), &FAs.Reserve},
-           {ES.intern((GlobalPrefix + "__orc_rt_finalize").str()),
+          EPC, *H,
+          {{EPC.intern((GlobalPrefix + "__orc_rt_reserve").str()), &FAs.Reserve},
+           {EPC.intern((GlobalPrefix + "__orc_rt_finalize").str()),
             &FAs.Finalize},
-           {ES.intern((GlobalPrefix + "__orc_rt_deallocate").str()),
+           {EPC.intern((GlobalPrefix + "__orc_rt_deallocate").str()),
             &FAs.Deallocate}}))
     return std::move(Err);
 
-  return std::make_unique<EPCGenericJITLinkMemoryManager>(
-      ES.getExecutorProcessControl(), FAs);
+  return std::make_unique<EPCGenericJITLinkMemoryManager>(EPC, std::move(FAs));
 }
 
 Expected<std::unique_ptr<jitlink::JITLinkMemoryManager::Allocation>>
index 319909f..e4ecd47 100644 (file)
@@ -14,30 +14,32 @@ namespace orc {
 
 /// Create from a ExecutorProcessControl instance.
 Expected<std::unique_ptr<EPCGenericMemoryAccess>>
-EPCGenericMemoryAccess::CreateUsingOrcRTFuncs(ExecutionSession &ES,
-                                              JITDylib &OrcRuntimeJD) {
+EPCGenericMemoryAccess::CreateUsingOrcRTFuncs(ExecutorProcessControl &EPC) {
+
+  auto H = EPC.loadDylib("");
+  if (!H)
+    return H.takeError();
 
   StringRef GlobalPrefix = "";
-  if (ES.getExecutorProcessControl().getTargetTriple().isOSBinFormatMachO())
+  if (EPC.getTargetTriple().isOSBinFormatMachO())
     GlobalPrefix = "_";
 
   FuncAddrs FAs;
   if (auto Err = lookupAndRecordAddrs(
-          ES, LookupKind::Static, makeJITDylibSearchOrder(&OrcRuntimeJD),
-          {{ES.intern((GlobalPrefix + "__orc_rt_write_uint8s_wrapper").str()),
+          EPC, *H,
+          {{EPC.intern((GlobalPrefix + "__orc_rt_write_uint8s_wrapper").str()),
             &FAs.WriteUInt8s},
-           {ES.intern((GlobalPrefix + "__orc_rt_write_uint16s_wrapper").str()),
+           {EPC.intern((GlobalPrefix + "__orc_rt_write_uint16s_wrapper").str()),
             &FAs.WriteUInt16s},
-           {ES.intern((GlobalPrefix + "__orc_rt_write_uint32s_wrapper").str()),
+           {EPC.intern((GlobalPrefix + "__orc_rt_write_uint32s_wrapper").str()),
             &FAs.WriteUInt32s},
-           {ES.intern((GlobalPrefix + "__orc_rt_write_uint64s_wrapper").str()),
+           {EPC.intern((GlobalPrefix + "__orc_rt_write_uint64s_wrapper").str()),
             &FAs.WriteUInt64s},
-           {ES.intern((GlobalPrefix + "__orc_rt_write_buffers_wrapper").str()),
+           {EPC.intern((GlobalPrefix + "__orc_rt_write_buffers_wrapper").str()),
             &FAs.WriteBuffers}}))
     return std::move(Err);
 
-  return std::make_unique<EPCGenericMemoryAccess>(
-      ES.getExecutorProcessControl(), FAs);
+  return std::make_unique<EPCGenericMemoryAccess>(EPC, std::move(FAs));
 }
 
 } // end namespace orc