[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
This commit is contained in:
Emilio Cota
2022-02-23 10:51:36 -05:00
parent e87c32e390
commit 011f653265
2 changed files with 9 additions and 2 deletions

View File

@@ -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;

View File

@@ -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)