[Mlir-commits] [mlir] 011f653 - [mlir] Add sectionMemoryMapper to ExecutionEngineOptions

Emilio Cota llvmlistbot at llvm.org
Wed Feb 23 11:57:07 PST 2022


Author: Emilio Cota
Date: 2022-02-23T14:56:50-05:00
New Revision: 011f653265e1c444a77fb24cf03b2ea7faa517b9

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

LOG: [mlir] Add sectionMemoryMapper to ExecutionEngineOptions

By specifying a sectionMemoryMapper, users can control how
memory for JIT code is allocated.

In particular, I need this in order to use a named memory
region so that profilers such as perf(1) can correctly label
execution cycles coming from JIT'ed code.

Reviewed-by: ezhulenev

Differential Revision: https://reviews.llvm.org/D120415

Added: 
    

Modified: 
    mlir/include/mlir/ExecutionEngine/ExecutionEngine.h
    mlir/lib/ExecutionEngine/ExecutionEngine.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/ExecutionEngine/ExecutionEngine.h b/mlir/include/mlir/ExecutionEngine/ExecutionEngine.h
index 8a2a870aec422..34fd7f21751ac 100644
--- a/mlir/include/mlir/ExecutionEngine/ExecutionEngine.h
+++ b/mlir/include/mlir/ExecutionEngine/ExecutionEngine.h
@@ -16,6 +16,7 @@
 #include "mlir/Support/LLVM.h"
 #include "llvm/ExecutionEngine/ObjectCache.h"
 #include "llvm/ExecutionEngine/Orc/LLJIT.h"
+#include "llvm/ExecutionEngine/SectionMemoryManager.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/Support/Error.h"
 
@@ -68,6 +69,11 @@ struct ExecutionEngineOptions {
   /// open and link the shared libraries for symbol resolution.
   ArrayRef<StringRef> sharedLibPaths = {};
 
+  /// Specifies an existing `sectionMemoryMapper` to be associated with the
+  /// compiled code. If none is provided, a default memory mapper that directly
+  /// calls into the operating system is used.
+  llvm::SectionMemoryManager::MemoryMapper *sectionMemoryMapper = nullptr;
+
   /// If `enableObjectCache` is set, the JIT compiler will create one to store
   /// the object generated for the given module.
   bool enableObjectCache = true;

diff  --git a/mlir/lib/ExecutionEngine/ExecutionEngine.cpp b/mlir/lib/ExecutionEngine/ExecutionEngine.cpp
index d8e778b9efb44..916d764a75dad 100644
--- a/mlir/lib/ExecutionEngine/ExecutionEngine.cpp
+++ b/mlir/lib/ExecutionEngine/ExecutionEngine.cpp
@@ -24,7 +24,6 @@
 #include "llvm/ExecutionEngine/Orc/IRTransformLayer.h"
 #include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
 #include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
-#include "llvm/ExecutionEngine/SectionMemoryManager.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/MC/SubtargetFeature.h"
 #include "llvm/MC/TargetRegistry.h"
@@ -252,7 +251,9 @@ ExecutionEngine::create(ModuleOp m, const ExecutionEngineOptions &options) {
   auto objectLinkingLayerCreator = [&](ExecutionSession &session,
                                        const Triple &tt) {
     auto objectLayer = std::make_unique<RTDyldObjectLinkingLayer>(
-        session, []() { return std::make_unique<SectionMemoryManager>(); });
+        session, [sectionMemoryMapper = options.sectionMemoryMapper]() {
+          return std::make_unique<SectionMemoryManager>(sectionMemoryMapper);
+        });
 
     // Register JIT event listeners if they are enabled.
     if (engine->gdbListener)


        


More information about the Mlir-commits mailing list