[llvm] b0818df - [ORC][LLJIT] Add a Pre-PlatformSetup-Setup function.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 22 16:00:53 PDT 2023


Author: Lang Hames
Date: 2023-09-22T16:00:46-07:00
New Revision: b0818df50a57ca2a50feac7b31ad4e8ee4fa7c15

URL: https://github.com/llvm/llvm-project/commit/b0818df50a57ca2a50feac7b31ad4e8ee4fa7c15
DIFF: https://github.com/llvm/llvm-project/commit/b0818df50a57ca2a50feac7b31ad4e8ee4fa7c15.diff

LOG: [ORC][LLJIT] Add a Pre-PlatformSetup-Setup function.

This function will be run prior to platform setup to provide LLJIT clients with
a chance to customize the LLJIT instance (e.g. install plugins) before the JIT
runtime is loaded.

The motivating use-case is debugger support: We want to install the debugger
plugin before the runtime is loaded (during platform setup) so that the runtime
itself can be debugged. A patch to do this will be committed shortly.

Added: 
    

Modified: 
    llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
    llvm/lib/ExecutionEngine/Orc/LLJIT.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
index ab54e0c2c288205..415ec7228f058de 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
@@ -319,6 +319,7 @@ class LLJITBuilderState {
   ProcessSymbolsJITDylibSetupFunction SetupProcessSymbolsJITDylib;
   ObjectLinkingLayerCreator CreateObjectLinkingLayer;
   CompileFunctionCreator CreateCompileFunction;
+  unique_function<Error(LLJIT &)> PrePlatformSetup;
   PlatformSetupFunction SetUpPlatform;
   unsigned NumCompileThreads = 0;
   bool EnableDebuggerSupport = false;
@@ -418,6 +419,19 @@ class LLJITBuilderSetters {
     return impl();
   }
 
+  /// Set a setup function to be run just before the PlatformSetupFunction is
+  /// run.
+  ///
+  /// This can be used to customize the LLJIT instance before the platform is
+  /// set up. E.g. By installing a debugger support plugin before the platform
+  /// is set up (when the ORC runtime is loaded) we enable debugging of the
+  /// runtime itself.
+  SetterImpl &
+  setPrePlatformSetup(unique_function<Error(LLJIT &)> PrePlatformSetup) {
+    impl().PrePlatformSetup = std::move(PrePlatformSetup);
+    return impl();
+  }
+
   /// Set up an PlatformSetupFunction.
   ///
   /// If this method is not called then setUpGenericLLVMIRPlatform

diff  --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index 18ab9e6b940fefe..4cab0f28aee725f 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -1054,6 +1054,13 @@ LLJIT::LLJIT(LLJITBuilderState &S, Error &Err)
     }
   }
 
+  if (S.PrePlatformSetup) {
+    if (auto Err2 = S.PrePlatformSetup(*this)) {
+      Err = std::move(Err2);
+      return;
+    }
+  }
+
   if (!S.SetUpPlatform)
     S.SetUpPlatform = setUpGenericLLVMIRPlatform;
 


        


More information about the llvm-commits mailing list