summaryrefslogtreecommitdiff
path: root/llvm/lib/ExecutionEngine/Orc/SimpleRemoteEPC.cpp
AgeCommit message (Collapse)Author
2025-10-20Reapply "[ORC] Replace ORC's baked-in dependence ... (#163027)" with … ↵Lang Hames
(#164340) …fixes. This reapplies c8c86efbbb5, which was reverted in 13ca8723d1b due to bot failures. Those failures were compilation errors exposed when LLVM is built with LLVM_ENABLE_EXPENSIVE_CHECKS=On. They have been fixed in this commit.
2025-10-20Revert "[ORC] Replace ORC's baked-in dependence tracking ... (#163027)"Lang Hames
Reverts commit c8c86efbbb55e51597c1bd8feb2e947bc0de3422 while I investigate bot failures, e.g. https://lab.llvm.org/buildbot/#/builders/187/builds/12743.
2025-10-20[ORC] Replace ORC's baked-in dependence tracking with WaitingOnGraph. (#163027)Lang Hames
WaitingOnGraph tracks waiting-on relationships between nodes (intended to represent symbols in an ORC program) in order to identify nodes that are *Ready* (i.e. are not waiting on any other nodes) or have *Failed* (are waiting on some node that cannot be produced). WaitingOnGraph replaces ORC's baked-in data structures that were tracking the same information (EmissionDepUnit, EmissionDepUnitInfo, ...). Isolating this information in a separate data structure simplifies the code, allows us to unit test it, and simplifies performance testing. The WaitingOnGraph uses several techniques to improve performance relative to the old data structures, including symbol coalescing ("SuperNodes") and symbol keys that don't perform unnecessary reference counting (NonOwningSymbolStringPtr). This commit includes unit tests for common dependence-tracking issues that have led to ORC bugs in the past.
2025-10-16[ORC] Align ExecutorSimpleMemoryManager w/ orc_rt::SimpleNativeMemoryMap ↵Lang Hames
(#163693) Teach ExecutorSimpleMemoryManager to handle slab reserve/release operations, plus separate initialize/deinitialize for regions within the slab. The release operation automatically deinitializes any regions within each slab that have not already been released. EPCGenericJITLinkMemoryManager is updated to use the reserve (allocate), initialize (finalize), and relesae (deallocate) operations. This brings ExecutorSimpleMemoryManager into alignment with the orc_rt::SimpleNativeMemoryMap class, allowing SimpleNativeMemoryMap to be used as a backend for EPCGenericJITLinkMemoryManager. A future commit will introduce a new MemoryMapper class that will make SimpleNativeMemoryMap usable as a backend for MapperJITLinkMemoryManager. This work will make it easier to re-use in-tree APIs and tools with the new ORC runtime.
2025-06-27[ORC] Add read operations to orc::MemoryAccess. (#145834)Lang Hames
This commit adds operations to orc::MemoryAccess for reading basic types (uint8_t, uint16_t, uint32_t, uint64_t, pointers, buffers, and strings) from executor memory. The InProcessMemoryAccess and EPCGenericMemoryAccess implementations are updated to support the new operations.
2025-06-26[ORC] Extract MemoryAccess from ExecutorProcessControl, break up header. ↵Lang Hames
(#145671) This moves the MemoryAccess interface out of the ExecutorProcessControl class and splits implementation classes InProcessMemoryManager and SelfExecutorProcessControl out of ExecutorProcessControl.h and into their own headers.
2025-03-29[ExecutionEngine] Avoid repeated hash lookups (NFC) (#133615)Kazu Hirata
2024-12-06[ORC] Provide default MemoryAccess in SimpleRemoteEPC, add WritePointers impl.Lang Hames
Make EPCGenericMemoryAccess the default implementation for the MemoryAccess object in SimpleRemoteEPC, and add support for the WritePointers operation to OrcTargetProcess (previously this operation was unimplemented and would have triggered an error if accessed in a remote-JIT setup). No testcase yet: This functionality requires cross-process JITing to test (or a much more elaborate unit-test setup). It can be tested once the new top-level ORC runtime project lands.
2024-11-19[ExecutionEngine] Remove unused includes (NFC) (#116749)Kazu Hirata
Identified with misc-include-cleaner.
2024-10-23[ORC] Move EPC load-dylib and lookup operations into their own class.Lang Hames
This keeps common operations together, and should make it easier to write re-usable dylib managers in the future (e.g. a DylibManager that uses the EPC's remote-execution APIs to implement load and lookup).
2024-02-12[ORC] Make EPCDynamicLibrarySearchGenerator asyncBen Langmuir
Switch the primary implementation of EPC lookupSymbols to be async, keeping a synchronous wrapper for compatibility. Use the new async implementation inside EPCDynamicLibrarySearchGenerator to work working towards a fully async search generator. Provide an asynchronous lookup API for EPCGenericDylibManager and adopt that from the SimpleRemoteEPC. This enables an end-to-end async EPCDynamicLibrarySearchGenerator. Note: currently we keep the current per-dlhandle lookup model, but a future improvement could do a single async call for a given lookup operation.
2023-04-02[ORC] Add a generic bootstrap key-value store to SimpleRemoteEPC.Lang Hames
SimpleRemoteEPC already included a "bootstrap symbols map" that could be used to communicate the addresses of symbols needed for JIT bootstrap. The new bootstrap map can be used to communicate arbitrary bootstrap values (encoded as SPS buffers). The bootstrap symbols map is kept as distinct becasue bootstrap symbols are significant, and having a known value type for them allows for better debug logging (we know how to render the values) and tooling (e.g. utils for adding all bootstrap symbols to a JITDylib).
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.
2023-03-31[ORC] Simplify some ExecutorAddr uses by removing getValue and formatv.Lang Hames
2023-03-27[ORC] Move most ORC APIs to ExecutorAddr, introduce ExecutorSymbolDef.Lang Hames
ExecutorAddr was introduced in b8e5f918166 as an eventual replacement for JITTargetAddress. ExecutorSymbolDef is introduced in this patch as a replacement for JITEvaluatedSymbol: ExecutorSymbolDef is an (ExecutorAddr, JITSymbolFlags) pair, where JITEvaluatedSymbol was a (JITTargetAddress, JITSymbolFlags) pair. A number of APIs had already migrated from JITTargetAddress to ExecutorAddr, but many of ORC's internals were still using the older type. This patch aims to address that. Some public APIs are affected as well. If you need to migrate your APIs you can use the following operations: * ExecutorAddr::toPtr replaces jitTargetAddressToPointer and jitTargetAddressToFunction. * ExecutorAddr::fromPtr replace pointerToJITTargetAddress. * ExecutorAddr(JITTargetAddress) creates an ExecutorAddr value from a JITTargetAddress. * ExecutorAddr::getValue() creates a JITTargetAddress value from an ExecutorAddr. JITTargetAddress and JITEvaluatedSymbol will remain in JITSymbol.h for now, but the aim will be to eventually deprecate and remove these types (probably when MCJIT and RuntimeDyld are deprecated).
2022-10-24[ORC] Use raw OS handle values, ExecutorAddr for EPC dylib handles.Lang Hames
Updates tpctypes::DylibHandle to be an ExecutorAddr (rather than a uint64_t), and SimpleExecutorDylibManager to hold and return raw OS handle values (as ExecutorAddrs) rather than index values into a map of DynamicLibrary instances. This will allow clients to use EPCGenericDylibManager in contexts where the existing DynamicLibrary interface is too limited to be used. (e.g. to look up JIT symbols in a dylib that was loaded with RTLD_LOCAL).
2022-08-11[ORC][COFF] Introduce COFFVCRuntimeBootstrapper.Sunho Kim
Introduces COFFVCRuntimeBootstrapper that loads/initialize vc runtime libraries. In COFF, we *must* jit-link vc runtime libraries as COFF relocation types have no proper way to deal with out-of-reach data symbols ragardless of linking mode. (even dynamic version msvcrt.lib have tons of static data symbols that must be jit-linked) This class tries to load vc runtime library files from msvc installations with an option to override the path. There are some complications when dealing with static version of vc runtimes. First, they need static initializers to be ran that requires COFFPlatform support but orc runtime will not be usable before vc runtimes are fully initialized. (as orc runtime will use msvc stl libraries) COFFPlatform that will be introduced in a following up patch will collect static initializers and run them manually in host before boostrapping itself. So, the user will have to do the following. 1. Create COFFPlatform that addes static initializer collecting passes. 2. LoadVCRuntime 3. InitializeVCRuntime 4. COFFPlatform.bootstrap() Second, the internal crt initialization function had to be reimplemented in orc side. There are other ways of doing this, but this is the simplest implementation that makes platform fully responsible for static initializer. The complication comes from the fact that crt initialization functions (such as acrt_initialize or dllmain_crt_process_attach) actually run all static initializers by traversing from `__xi_a` symbol to `__xi_z`. This requires symbols to be contiguously allocated in sections alphabetically sorted in memory, which is not possible right now and not practical in jit setting. We might ignore emission of `__xi_a` and `__xi_z` symbol and allocate them ourselves, but we have to take extra care after orc runtime boostrap has been done -- as that point orc runtime should be the one running the static initializers. Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D130456
2021-11-01[ORC] Run incoming jit-dispatch calls via the TaskDispatcher in SimpleRemoteEPC.Lang Hames
Handlers for jit-dispatch calls are allowed to make their own EPC calls, so we don't want to run these on the handler thread.
2021-10-13[ORC] Use a Setup object for SimpleRemoteEPC construction.Lang Hames
SimpleRemoteEPC notionally allowed subclasses to override the createMemoryManager and createMemoryAccess methods to use custom objects, but could not actually be subclassed in practice (The construction process in SimpleRemoteEPC::Create could not be re-used). Instead of subclassing, this commit adds a SimpleRemoteEPC::Setup class that can be used by clients to set up the memory manager and memory access members. A default-constructed Setup object results in no change from previous behavior (EPCGeneric* memory manager and memory access objects used by default).
2021-10-12[ORC] Shut down dispatcher in ExecutorProcessControl implementations.Lang Hames
f3411616896 added a task dispatcher for async handlers, but didn't add a TaskDispatcher::shutdown call to SelfExecutorProcessControl or SimpleRemoteEPC. This patch adds the missing call, which ensures that we don't destroy the dispatcher while tasks are still running. This should fix the use-after-free crash seen in https://lab.llvm.org/buildbot/#/builders/5/builds/13063
2021-10-11[ORC] Propagate errors to handlers when sendMessage fails.Lang Hames
In SimpleRemoteEPC, calls to from callWrapperAsync to sendMessage may fail. The handlers may or may not be sent failure messages by handleDisconnect, depending on when that method is run. This patch adds a check for an un-failed handler, and if it finds one sends it a failure message.
2021-10-11[Orc] Handle hangup messages in SimpleRemoteEPCStefan Gränitz
On the controller-side, handle `Hangup` messages from the executor. The executor passed `Error::success()` or a failure message as payload. Hangups cause an immediate disconnect of the transport layer. The disconnect function may be called later again and so implementations should be prepared. `FDSimpleRemoteEPCTransport::disconnect()` already has a flag to check that: https://github.com/llvm/llvm-project/blob/cd1bd95d8707371da0e4f75cd01669c427466931/llvm/lib/ExecutionEngine/Orc/Shared/SimpleRemoteEPCUtils.cpp#L112 Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D111527
2021-10-10[ORC] Add optional RunPolicy to ExecutorProcessControl::callWrapperAsync.Lang Hames
The callWrapperAsync and callSPSWrapperAsync methods take a handler object that is run on the return value of the call when it is ready. The new RunPolicy parameters allow clients to control how these handlers are run. If no policy is specified then the handler will be packaged as a GenericNamedTask and dispatched using the ExecutorProcessControl's TaskDispatch member. Callers can use the ExecutorProcessControl::RunInPlace policy to cause the handler to be run directly instead, which may be preferrable for simple handlers, or they can write their own policy object (e.g. to dispatch as some other kind of Task, rather than GenericNamedTask).
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-26[ORC] Fix SimpleRemoteEPC data races.Lang Hames
Adds a 'start' method to SimpleRemoteEPCTransport to defer transport startup until the client has been configured. This avoids races on client members if the first messages arrives while the client is being configured. Also fixes races on the file descriptors in FDSimpleRemoteEPCTransport.
2021-09-26[ORC][llvm-jitlink] Add debugging output to SimpleRemoteEPC (and Server).Lang Hames
Also adds an optional 'debug' argument to the llvm-jitlink-executor tool to enable debug-logging.
2021-09-26[ORC] Wait for handleDisconnect to complete in SimpleRemoteEPC::disconnect.Lang Hames
Disconnect should block until handleDisconnect completes, otherwise we might destroy the SimpleRemoteEPC instance while it's still in use. Thanks to Dave Blaikie for helping me track this down.
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-23[ORC] Introduce EPCGenericDylibManager / SimpleExecutorDylibManager.Lang Hames
EPCGenericDylibManager provides an interface for loading dylibs and looking up symbols in the executor, implemented using EPC-calls to functions in the executor. SimpleExecutorDylibManager is an executor-side service that provides the functions used by EPCGenericDylibManager. SimpleRemoteEPC is updated to use an EPCGenericDylibManager instance to implement the ExecutorProcessControl loadDylib and lookup methods. In a future commit these methods will be removed, and clients updated to use EPCGenericDylibManagers directly.
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-12[ORC] Add bootstrap symbols to ExecutorProcessControl.Lang Hames
Bootstrap symbols are symbols whose addresses may be required to bootstrap the rest of the JIT. The bootstrap symbols map generalizes the existing JITDispatchInfo class provide an arbitrary map of symbol names to addresses. The JITDispatchInfo class will be replaced by bootstrap symbols with reserved names in upcoming commits.
2021-09-12[ORC] Fix out-of-range comparison errors.Lang Hames
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.