summaryrefslogtreecommitdiff
path: root/llvm/lib/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.cpp
AgeCommit message (Collapse)Author
2024-11-19[ExecutionEngine] Remove unused includes (NFC) (#116749)Kazu Hirata
Identified with misc-include-cleaner.
2023-03-31[ORC] Remove redundant ExecutorAddr temporaries.Lang Hames
Most ORC APIs work with ExecutorAddr by default since 8b1771bd9f3, so we don't need to wrap these values in ExecutorAddr(...) calls any more.
2022-10-03[ORC][JITLink] Move MemoryFlags.h (MemProt, AllocGroup,...) from JITLink to ORC.Lang Hames
Moving these types to OrcShared eliminates the need for the separate WireProtectionFlags type.
2022-07-23Revert "[Orc] Use default member initialization (NFC)"Kazu Hirata
This reverts commit d534967b6667c468b12e9ed5e3c482f590dde633. The patch causes build failures, such as: https://lab.llvm.org/buildbot/#/builders/121/builds/21760
2022-07-23[Orc] Use default member initialization (NFC)Kazu Hirata
Identified with modernize-use-default-member-init
2022-01-08[ORC][JITLink] Merge JITLink AllocActionCall and ORC WrapperFunctionCall.Lang Hames
These types performed identical roles. Merging them simplifies interoperability between JITLink and ORC APIs (allowing us to address a few FIXMEs).
2022-01-06Re-apply "[JITLink] Update JITLink to use ExecutorAddr rather... " with fixes.Lang Hames
This re-applies 133f86e95492b2a00b944e070878424cfa73f87c, which was reverted in c5965a411c635106a47738b8d2e24db822b7416f while I investigated bot failures. The original failure contained an arithmetic conversion think-o (on line 419 of EHFrameSupport.cpp) that could cause failures on 32-bit platforms. The issue should be fixed in this patch.
2022-01-06Revert "[JITLink] Update JITLink to use ExecutorAddr rather than..."Lang Hames
This reverts commit 133f86e95492b2a00b944e070878424cfa73f87c while I investigate the bot failures at https://lab.llvm.org/buildbot#builders/186/builds/3370.
2022-01-06[JITLink] Update JITLink to use ExecutorAddr rather than JITTargetAddress.Lang Hames
ExecutorAddr is the preferred representation for executor process addresses now.
2021-10-28Reapply e32b1eee6aa "[ORC] Change SPSExecutorAddr serialization,..." with fixes.Lang Hames
This re-applies e32b1eee6aab52e2b7b75ee15e506b3e7dd30e68, which was reverted in 20675d8f7dab293172266fdde426c2173b5b3997 due to broken unit tests. This patch includes fixes for the tests.
2021-10-27Revert "[ORC] Change SPSExecutorAddr serialization, SupportFunctionCall struct."Lang Hames
This reverts commit e32b1eee6aab52e2b7b75ee15e506b3e7dd30e68. Reverting while I fix some broken unit tests.
2021-10-27[ORC] Change SPSExecutorAddr serialization, SupportFunctionCall struct.Lang Hames
SPSExecutorAddr will now be serializable to/from ExecutorAddr, rather than uint64_t. This improves type safety when working with serialized addresses. Also updates the SupportFunctionCall to use an ExecutorAddrRange (rather than a separate ExecutorAddr addr and uint64_t size field), and updates the tpctypes::*Write data structures to use ExecutorAddr rather than JITTargetAddress.
2021-10-11[ORC] More attempts to work around compiler failures.Lang Hames
Commit 731f991cdc4 seems to have helped, but did not catch all instances (see https://lab.llvm.org/buildbot/#/builders/193/builds/104). Switch more inner structs to C++98 initializers to work around the issue. Add FIXMEs to revisit in the future.
2021-10-11Re-apply e50aea58d59, "Major JITLinkMemoryManager refactor". with fixes.Lang Hames
Adds explicit narrowing casts to JITLinkMemoryManager.cpp. Honors -slab-address option in llvm-jitlink.cpp, which was accidentally dropped in the refactor. This effectively reverts commit 6641d29b70993bce6dbd7e0e0f1040753d38842f.
2021-10-11Revert "[JITLink][ORC] Major JITLinkMemoryManager refactor."Lang Hames
This reverts commit e50aea58d59c8cfae807a7fee21c4227472c0678 while I investigate bot failures.
2021-10-11[JITLink][ORC] Major JITLinkMemoryManager refactor.Lang Hames
This commit substantially refactors the JITLinkMemoryManager API to: (1) add asynchronous versions of key operations, (2) give memory manager implementations full control over link graph address layout, (3) enable more efficient tracking of allocated memory, and (4) support "allocation actions" and finalize-lifetime memory. Together these changes provide a more usable API, and enable more powerful and efficient memory manager implementations. To support these changes the JITLinkMemoryManager::Allocation inner class has been split into two new classes: InFlightAllocation, and FinalizedAllocation. The allocate method returns an InFlightAllocation that tracks memory (both working and executor memory) prior to finalization. The finalize method returns a FinalizedAllocation object, and the InFlightAllocation is discarded. Breaking Allocation into InFlightAllocation and FinalizedAllocation allows InFlightAllocation subclassses to be written more naturally, and FinalizedAlloc to be implemented and used efficiently (see (3) below). In addition to the memory manager changes this commit also introduces a new MemProt type to represent memory protections (MemProt replaces use of sys::Memory::ProtectionFlags in JITLink), and a new MemDeallocPolicy type that can be used to indicate when a section should be deallocated (see (4) below). Plugin/pass writers who were using sys::Memory::ProtectionFlags will have to switch to MemProt -- this should be straightworward. Clients with out-of-tree memory managers will need to update their implementations. Clients using in-tree memory managers should mostly be able to ignore it. Major features: (1) More asynchrony: The allocate and deallocate methods are now asynchronous by default, with synchronous convenience wrappers supplied. The asynchronous versions allow clients (including JITLink) to request and deallocate memory without blocking. (2) Improved control over graph address layout: Instead of a SegmentRequestMap, JITLinkMemoryManager::allocate now takes a reference to the LinkGraph to be allocated. The memory manager is responsible for calculating the memory requirements for the graph, and laying out the graph (setting working and executor memory addresses) within the allocated memory. This gives memory managers full control over JIT'd memory layout. For clients that don't need or want this degree of control the new "BasicLayout" utility can be used to get a segment-based view of the graph, similar to the one provided by SegmentRequestMap. Once segment addresses are assigned the BasicLayout::apply method can be used to automatically lay out the graph. (3) Efficient tracking of allocated memory. The FinalizedAlloc type is a wrapper for an ExecutorAddr and requires only 64-bits to store in the controller. The meaning of the address held by the FinalizedAlloc is left up to the memory manager implementation, but the FinalizedAlloc type enforces a requirement that deallocate be called on any non-default values prior to destruction. The deallocate method takes a vector<FinalizedAlloc>, allowing for bulk deallocation of many allocations in a single call. Memory manager implementations will typically store the address of some allocation metadata in the executor in the FinalizedAlloc, as holding this metadata in the executor is often cheaper and may allow for clean deallocation even in failure cases where the connection with the controller is lost. (4) Support for "allocation actions" and finalize-lifetime memory. Allocation actions are pairs (finalize_act, deallocate_act) of JITTargetAddress triples (fn, arg_buffer_addr, arg_buffer_size), that can be attached to a finalize request. At finalization time, after memory protections have been applied, each of the "finalize_act" elements will be called in order (skipping any elements whose fn value is zero) as ((char*(*)(const char *, size_t))fn)((const char *)arg_buffer_addr, (size_t)arg_buffer_size); At deallocation time the deallocate elements will be run in reverse order (again skipping any elements where fn is zero). The returned char * should be null to indicate success, or a non-null heap-allocated string error message to indicate failure. These actions allow finalization and deallocation to be extended to include operations like registering and deregistering eh-frames, TLS sections, initializer and deinitializers, and language metadata sections. Previously these operations required separate callWrapper invocations. Compared to callWrapper invocations, actions require no extra IPC/RPC, reducing costs and eliminating a potential source of errors. Finalize lifetime memory can be used to support finalize actions: Sections with finalize lifetime should be destroyed by memory managers immediately after finalization actions have been run. Finalize memory can be used to support finalize actions (e.g. with extra-metadata, or synthesized finalize actions) without incurring permanent memory overhead.
2021-10-11[ORC] Destroy FinalizeErr if there is a serialization error.Lang Hames
If there is a serialization error then FinalizeErr should never be set, so we can use cantFail rather than consumeError here.
2021-10-10[ORC] Reorder callWrapperAsync and callSPSWrapperAsync parameters.Lang Hames
The callee address is now the first parameter and the 'SendResult' function the second. This change improves consistentency with the non-async functions where the callee is the first address and the return value the second.
2021-09-27[ORC] Switch from JITTargetAddress to ExecutorAddr for EPC-call APIs.Lang Hames
Part of the ongoing move to ExecutorAddr.
2021-09-23[ORC] Rename ExecutorAddress to ExecutorAddr.Lang Hames
Removing the 'ess' suffix improves the ergonomics without sacrificing clarity. Since this class is likely to be used more frequently in the future it's worth some short term pain to fix this now.
2021-09-17[ORC] Add finalization & deallocation actions, SimpleExecutorMemoryManager classLang Hames
Finalization and deallocation actions are a key part of the upcoming JITLinkMemoryManager redesign: They generalize the existing finalization and deallocate concepts (basically "copy-and-mprotect", and "munmap") to include support for arbitrary registration and deregistration of parts of JIT linked code. This allows us to register and deregister eh-frames, TLV sections, language metadata, etc. using regular memory management calls with no additional IPC/RPC overhead, which should both improve JIT performance and simplify interactions between ORC and the ORC runtime. The SimpleExecutorMemoryManager class provides executor-side support for memory management operations, including finalization and deallocation actions. This support is being added in advance of the rest of the memory manager redesign as it will simplify the introduction of an EPC based RuntimeDyld::MemoryManager (since eh-frame registration/deregistration will be expressible as actions). The new RuntimeDyld::MemoryManager will in turn allow us to remove older remote allocators that are blocking the rest of the memory manager changes.
2021-09-14[ORC] Add Shared/OrcRTBridge, and TargetProcess/OrcRTBootstrap.Lang Hames
This is a small first step towards reorganization of the ORC libraries: Declarations for types and function names (as strings) to be found in the "ORC runtime bootstrap" set are moved into OrcRTBridge.h / OrcRTBridge.cpp. The current implementation of the "ORC runtime bootstrap" functions is moved into OrcRTBootstrap.h and OrcRTBootstrap.cpp. It is likely that this code will eventually be moved into ORT-RT proper (in compiler RT). The immediate goal of this change is to make these bootstrap functions usable for clients other than SimpleRemoteEPC/SimpleRemoteEPCServer. The first planned client is a new RuntimeDyld::MemoryManager that will run over EPC, which will allow us to remove the old OrcRemoteTarget code.
2021-09-12Re-apply bb27e456435 and 5629afea910 with fixes.Lang Hames
This reapplies bb27e4564355243e479cab40885d6e0f7f640572 (SimpleRemoteEPC support) and 2269a941a450a0d395161cfb792be58870b2875b (#include <mutex> fix) with further fixes to support building with LLVM_ENABLE_THREADS=Off.
2021-09-11Revert 5629afea910 and bb27e456435 while I look into bot failures.Lang Hames
This reverts commit 5629afea9109d3b72064cbe70e1ca91ffb9dc0a2 ("[ORC] Add missing include."), and bb27e4564355243e479cab40885d6e0f7f640572 ("[ORC] Add SimpleRemoteEPC: ExecutorProcessControl over SPS + abstract transport."). The SimpleRemoteEPC patch currently assumes availability of threads, and needs to be rewritten with LLVM_ENABLE_THREADS guards.
2021-09-11[ORC] Add SimpleRemoteEPC: ExecutorProcessControl over SPS + abstract transport.Lang Hames
SimpleRemoteEPC is an ExecutorProcessControl implementation (with corresponding new server class) that uses ORC SimplePackedSerialization (SPS) to serialize and deserialize EPC-messages to/from byte-buffers. The byte-buffers are sent and received via a new SimpleRemoteEPCTransport interface that can be implemented to run SimpleRemoteEPC over whatever underlying transport system (IPC, RPC, network sockets, etc.) best suits your use case. The SimpleRemoteEPCServer class provides executor-side support. It uses a customizable SimpleRemoteEPCServer::Dispatcher object to dispatch wrapper function calls to prevent the RPC thread from being blocked (a problem in some earlier remote-JIT server implementations). Almost all functionality (beyond the bare basics needed to bootstrap) is implemented as wrapper functions to keep the implementation simple and uniform. Compared to previous remote JIT utilities (OrcRemoteTarget*, OrcRPCExecutorProcessControl), more consideration has been given to disconnection and error handling behavior: Graceful disconnection is now always initiated by the ORC side of the connection, and failure at either end (or in the transport) will result in Errors being delivered to both ends to enable controlled tear-down of the JIT and Executor (in the Executor's case this means "as controlled as the JIT'd code allows"). The introduction of SimpleRemoteEPC will allow us to remove other remote-JIT support from ORC (including the legacy OrcRemoteTarget* code used by lli, and the OrcRPCExecutorProcessControl and OrcRPCEPCServer classes), and then remove ORC RPC itself. The llvm-jitlink and llvm-jitlink-executor tools have been updated to use SimpleRemoteEPC over file descriptors. Future commits will move lli and other tools and example code to this system, and remove ORC RPC.
2021-09-11[ORC] Use EPC for EPCGeneric MemoryAccess / JITLinkMemoryManager construction.Lang Hames
This allows these classes to be created during EPC construction, before an ExecutionSession is available.
2021-09-03[ORC] Static cast more uint64_t to size_tDavid Spickett
These instances don't have an obvious way to fail nicely so I've just asserted they are within range. Fixes the Arm 32 bit builds.
2021-09-03[ORC] Add EPCGenericJITLinkMemoryManager: memory management via EPC calls.Lang Hames
All ExecutorProcessControl subclasses must provide a JITLinkMemoryManager object that can be used to allocate memory in the executor process. The EPCGenericJITLinkMemoryManager class provides an off-the-shelf JITLinkMemoryManager implementation for JITs that do not need (or cannot provide) a specialized JITLinkMemoryManager implementation. This simplifies the process of creating new ExecutorProcessControl implementations.