Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:52

0001 //===---------------- SimpleExecutorMemoryManager.h -------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // A simple allocator class suitable for basic remote-JIT use.
0010 //
0011 // FIXME: The functionality in this file should be moved to the ORC runtime.
0012 //
0013 //===----------------------------------------------------------------------===//
0014 
0015 #ifndef LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_SIMPLEEXECUTORMEMORYMANAGER_H
0016 #define LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_SIMPLEEXECUTORMEMORYMANAGER_H
0017 
0018 #include "llvm/ADT/DenseMap.h"
0019 #include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
0020 #include "llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h"
0021 #include "llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h"
0022 #include "llvm/ExecutionEngine/Orc/TargetProcess/ExecutorBootstrapService.h"
0023 #include "llvm/Support/Error.h"
0024 
0025 #include <mutex>
0026 
0027 namespace llvm {
0028 namespace orc {
0029 namespace rt_bootstrap {
0030 
0031 /// Simple page-based allocator.
0032 class SimpleExecutorMemoryManager : public ExecutorBootstrapService {
0033 public:
0034   virtual ~SimpleExecutorMemoryManager();
0035 
0036   Expected<ExecutorAddr> allocate(uint64_t Size);
0037   Error finalize(tpctypes::FinalizeRequest &FR);
0038   Error deallocate(const std::vector<ExecutorAddr> &Bases);
0039 
0040   Error shutdown() override;
0041   void addBootstrapSymbols(StringMap<ExecutorAddr> &M) override;
0042 
0043 private:
0044   struct Allocation {
0045     size_t Size = 0;
0046     std::vector<shared::WrapperFunctionCall> DeallocationActions;
0047   };
0048 
0049   using AllocationsMap = DenseMap<void *, Allocation>;
0050 
0051   Error deallocateImpl(void *Base, Allocation &A);
0052 
0053   static llvm::orc::shared::CWrapperFunctionResult
0054   reserveWrapper(const char *ArgData, size_t ArgSize);
0055 
0056   static llvm::orc::shared::CWrapperFunctionResult
0057   finalizeWrapper(const char *ArgData, size_t ArgSize);
0058 
0059   static llvm::orc::shared::CWrapperFunctionResult
0060   deallocateWrapper(const char *ArgData, size_t ArgSize);
0061 
0062   std::mutex M;
0063   AllocationsMap Allocations;
0064 };
0065 
0066 } // end namespace rt_bootstrap
0067 } // end namespace orc
0068 } // end namespace llvm
0069 
0070 #endif // LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_SIMPLEEXECUTORMEMORYMANAGER_H