summaryrefslogtreecommitdiff
path: root/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp
AgeCommit message (Collapse)Author
2025-11-02[llvm] Use "= default" (NFC) (#166088)Kazu Hirata
Identified with modernize-use-equals-default.
2025-10-15Revert "[ORC] Make runAllocActions and runDeallocActions asynchorous." (#163480)Lang Hames
This reverts commit 3b5842c9c41a441280100045ef62bb8a0fe7200f. The intent of the original commit was to begin enabling asynchronous alloation actions (calls attached to JIT'd memory initialization and deinitialization). The asynchronous allocation actions scheme was fleshed-out in a development branch, but ran into an issue: Functions implementing actions are allowed to live in JIT'd code (e.g. in the ORC runtime), but we can't genally rely on tail-call elimination kicking in. This resulting in dealloc actions returning via stack frames that had been deallocated, triggering segfaults. It's possible that there are other approaches that would allow asynchronous allocation actions to work, but they're not on the critical path for JIT improvements so for now we'll just revert.
2025-10-13[ORC] Add LinkGraph& argument to MemoryMapper::prepare. (#163121)Lang Hames
This gives MemoryMapper implementations a chance to allocate working memory using the LinkGraph's allocator.
2025-03-14[ORC] Make runAllocActions and runDeallocActions asynchorous.Lang Hames
Part of ongoing work to make core ORC operations asynchronous. This only affects the runner utilities, not the AllocationActions themselves. The AllocationActions will be made asynchronous in a future patch.
2025-03-07[z/OS] Add call to shmctl() to release shared memory on z/OS (#130163)Zibi Sarbinowski
This PR will solve the issue with leaking shared memory we have after running llvm lit test on z/OS. In particular llvm/unittests/ExecutionEngine/Orc/SharedMemoryMapperTest.cpp was causing the leak.
2025-02-28[ExecutionEngine] Avoid repeated hash lookups (NFC) (#129191)Kazu Hirata
2024-11-19[ExecutionEngine] Remove unused includes (NFC) (#116749)Kazu Hirata
Identified with misc-include-cleaner.
2024-08-30[NFC] Add explicit #include llvm-config.h where its macros are used. (#106621)Daniil Fukalov
Without these explicit includes, removing other headers, who implicitly include llvm-config.h, may have non-trivial side effects.
2024-04-25[z/OS] Implement shared memory handling for JIT (#89933)Fanbo Meng
Fix 'use of undeclared identifier' build errors for shm_ functions on z/OS by implementing the functionality using shmget(), shmat(), and shmdt(). Use the BLAKE3 hash to map the name of the shared memory to a key. --------- Co-authored-by: Kai Nacke <kai.peter.nacke@ibm.com>
2024-03-08[llvm][Support] Add and use errnoAsErrorCode (#84423)Michael Spencer
LLVM is inconsistent about how it converts `errno` to `std::error_code`. This can cause problems because values outside of `std::errc` compare differently if one is system and one is generic on POSIX systems. This is even more of a problem on Windows where use of the system category is just wrong, as that is for Windows errors, which have a completely different mapping than POSIX/generic errors. This patch fixes one instance of this mistake in `JSONTransport.cpp`. This patch adds `errnoAsErrorCode()` which makes it so people do not need to think about this issue in the future. It also cleans up a lot of usage of `errno` in LLVM and Clang.
2023-09-28[ORC] Rename MemLifetimePolicy to MemLifetime.Lang Hames
The *Policy suffix came from the earlier MemAllocPolicy type, where it was included to distinguish the type from a memory-allocation operation. MemLifetime is a noun already, so the *Policy suffix is just dead weight now.
2023-03-18Re-apply "[JITLink][ORC] Rename MemDeallocPolicy to MemLifetime..." with fixes.Lang Hames
This reapplies 2cc64df0bd6a802eab592dbc282463c3e4a4281c, which was reverted in 5379c46d490640bfa80283e00240b6f1006092b4 due to bot failures. The new patch contains fixes to ELFLinkGraphBuilder.h to better handle non-SHT_ALLOC sections (these were being accidentally skipped in the previous patch), and to skip SHT_NULL sections.
2023-03-17Revert "[JITLink][ORC] Rename MemDeallocPolicy to MemLifetimePolicy, add ..."Lang Hames
This reverts commit 2cc64df0bd6a802eab592dbc282463c3e4a4281c while I investigate bot failures (e.g. https://lab.llvm.org/buildbot/#/builders/3/builds/23081).
2023-03-17[JITLink][ORC] Rename MemDeallocPolicy to MemLifetimePolicy, add NoAlloc option.Lang Hames
The original MemDeallocPolicy had two options: * Standard: allocated memory lives until deallocated or abandoned. * Finalize: allocated memory lives until all finalize actions have been run, then is destroyed. This patch introduces a new 'NoAlloc' option. NoAlloc indicates that the section should be ignored by the JITLinkMemoryManager -- the memory manager should allocate neither working memory nor executor address space to blocks in NoAlloc sections. The NoAlloc option is intended to support metadata sections (e.g. debug info) that we want to keep in the graph and have fixed up if necessary, but don't want allocated or transmitted to the executor (or we want that allocation and transmission to be managed manually by plugins). Since NoAlloc blocks are ignored by the JITLinkMemoryManager they will not have working memory allocated to them by default post-allocation. Clients wishing to modify the content of a block in a NoAlloc section should call `Block::getMutableMemory(LinkGraph&)` to get writable memory allocated on the LinkGraph's allocator (this memory will exist for the lifetime of the graph). If no client requests mutable memory prior to the fixup phase then the generic link algorithm will do so when it encounters the first edge in any given block. Addresses of blocks in NoAlloc sections are initialized by the LinkGraph creator (a LinkGraphBuilder, if the graph is generated from an object file), and should not be modified by the JITLinkMemoryManager. Plugins are responsible for updating addresses if they add/remove content from these sections. The meaning of addresses in NoAlloc-sections is backend/plugin defined, but for fixup purposes they will be treated the same as addresses in Standard/Finalize sections. References from Standard/Finalize sections to NoAlloc sections are expected to be common (these represent metadata tracking executor addresses). References from NoAlloc sections to Standard/Finalize sections are expected to be rare/non-existent (they would represent JIT'd code / data tracking metadata in the controller, which would be surprising). LinkGraphBuilders and specific backends may impose additional constraints on edges between Standard/Finalize and NoAlloc sections where required for correctness. Differential Revision: https://reviews.llvm.org/D146183
2022-12-02Add void cast for preprocessor-conditionall-unused loop variableDavid Blaikie
Fixing -Wunused -Werror build on Android.
2022-10-05[Orc] Fix the SharedMemoryMapper dtorAlexandre Ganea
As briefly discussed on https://reviews.llvm.org/rG1134d3a03facccd75efc5385ba46918bef94fcb6, fix the unintended copy while iterating on Reservations and add a mutex guard, to be symmetric with other usages of Reservations. Differential revision: https://reviews.llvm.org/D134212
2022-10-03[ORC] Don't unnecessarily copy collection element.Lang Hames
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-08-30[ORC] Update mapper deinitialize functions to deinitialize in reverse order.Lang Hames
This updates the ExecutorSharedMemoryMapperService::deinitialize and InProcessMemoryMapper::deinitialize methods to deinitialize in reverse order, bringing them into alignment with the behavior of InProcessMemoryManager::deallocate and SimpleExecutorMemoryManager::deallocate. Reverse deinitialization is required because later allocations can depend on earlier ones. This fixes failures in the ORC runtime test suite.
2022-08-27[Orc] Take offset inside slab into account in SharedMemoryMapperAnubhab Ghosh
SharedMemoryMapper assumed each reservation will have its corresponding allocations starting from the beginning. However with the introduction of the slab allocator, there can be a possible offset from the start from where the initialization is being performed. This commit also simplifies the logic for finding the parent reservation and makes the assert messages consistent.
2022-08-21[Orc] Provide correct Reservation address for slab allocationsAnubhab Ghosh
When slab allocator is used, the MappingBase is not necessarily the same as the original reservation base as the allocation could be a part of the whole reservation. In this case the original reservation address needs to be passed to ExecutorSharedMemoryMapperService to associate the new allocation with the original reservation. Differential Revision: https://reviews.llvm.org/D132313
2022-08-21[Orc] Only unmap shared memory in controller process destructorAnubhab Ghosh
By the time SharedMemoryMapper destructor is called, the RPC connection is no longer available causing the release() call to always fail. Instead at this point only shared memory regions can be unmapped safely. Deinitializers are called and mapped memory is released at the executor side by ExecutorSharedMemoryMapperService::shutdown() instead. Memory can also be released earlier by calling release() earlier before RPC connection is closed. Differential Revision: https://reviews.llvm.org/D132313
2022-08-13Reapply [Orc] Properly deallocate mapped memory in MapperJITLinkMemoryManagerAnubhab Ghosh
When memory is deallocated from MapperJITLinkMemoryManager deinitialize actions are run through mapper and in case of InProcessMapper, memory protections of the region are reset to read/write as they were previously changed and can be reused in future. Differential Revision: https://reviews.llvm.org/D131768
2022-08-13Revert "[Orc] Properly deallocate mapped memory in MapperJITLinkMemoryManager"Anubhab Ghosh
This reverts commit 143555b2ed30746fbcc8ff84e9cef4267688f110.
2022-08-13[Orc] Properly deallocate mapped memory in MapperJITLinkMemoryManagerAnubhab Ghosh
When memory is deallocated from MapperJITLinkMemoryManager deinitialize actions are run through mapper and in case of InProcessMapper, memory protections of the region are reset to read/write as they were previously changed and can be reused in future. Differential Revision: https://reviews.llvm.org/D131768
2022-08-04[ORC] Actually propagate memory unmapping errors on WindowsMartin Storsjö
This fixes warnings like these: ../lib/ExecutionEngine/Orc/MemoryMapper.cpp:364:9: warning: ignoring return value of function declared with 'warn_unused_result' attribute [-Wunused-result] joinErrors(std::move(Err), ^~~~~~~~~~ ~~~~~~~~~~~~~~~ Differential Revision: https://reviews.llvm.org/D131056
2022-08-01[Orc] Disable use of shared memory on AndroidAnubhab Ghosh
shm_open and shm_unlink are not available on Android. This commit disables SharedMemoryMapper on Android until a better solution is available. https://android.googlesource.com/platform/bionic/+/refs/heads/master/docs/status.md https://github.com/llvm/llvm-project/issues/56812 Differential Revision: https://reviews.llvm.org/D130814
2022-07-20[ORC] Add a new MemoryMapper-based JITLinkMemoryManager implementation.Anubhab Ghosh
MapperJITLinkMemoryManager supports executor memory management using any implementation of MemoryMapper to do the transfer such as InProcessMapper or SharedMemoryMapper. Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D129495
2022-07-19Re-re-apply 5acd47169884, Add a shared-memory based orc::MemoryMapper...Anubhab Ghosh
...with more fixes. The original patch was reverted in 3e9cc543f22 due to bot failures caused by a missing dependence on librt. That issue was fixed in 32d8d23cd0, but that commit also broke sanitizer bots due to a bug in SimplePackedSerialization: empty ArrayRef<char>s triggered a zero-byte memcpy from a null source. The ArrayRef<char> serialization issue was fixed in 67220c2ad7, and this patch has also been updated with a new custom SharedMemorySegFinalizeRequest message that should avoid serializing empty ArrayRefs in the first place. https://reviews.llvm.org/D128544
2022-07-15Revert "Re-apply 5acd47169884, Add a shared-memory based orc::MemoryMapper, ↵Mitch Phillips
with fixes." This reverts commit 32d8d23cd0b2d4d010eb112dfe5216f11b2681f9. Reason: Broke the UBSan buildbots. See more details on Phabricator: https://reviews.llvm.org/D128544
2022-07-15Re-apply 5acd47169884, Add a shared-memory based orc::MemoryMapper, with fixes.Anubhab Ghosh
The original commit was reverted in 3e9cc543f223 due to buildbot failures, which should be fixed by the addition of dependencies on librt. Differential Revision: https://reviews.llvm.org/D128544
2022-07-14Revert "[ORC] Add a shared-memory based orc::MemoryMapper."Cullen Rhodes
This reverts commit 5acd471698849d9e322a29e6ca08791e8d447b7b. Breaks shared library build with: ld.lld-12: error: undefined symbol: shm_open >>> referenced by ExecutorSharedMemoryMapperService.cpp:68 (/home/culrho01/llvm-project/llvm/lib/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.cpp:68) >>> lib/ExecutionEngine/Orc/TargetProcess/CMakeFiles/LLVMOrcTargetProcess.dir/ExecutorSharedMemoryMapperService.cpp.o:(llvm::orc::rt_bootstrap::ExecutorSharedMemoryMapperService::reserve[abi:cxx11](unsigned long)) >>> did you mean: sem_open >>> defined in: /usr/bin/../lib/gcc/aarch64-linux-gnu/9/../../../aarch64-linux-gnu/libpthread.so
2022-07-14Revert "[ORC] Fix compilation on mingw"Cullen Rhodes
This reverts commit 46b1a7c5f9e6841016078d32728bb0d205336df5. Parent commit breaks shared library build, reverting both commits.
2022-07-14[ORC] Fix compilation on mingwMartin Storsjö
Explicitly call the -W suffixed API functions when passing wchar based strings.
2022-07-13[ORC] Add a shared-memory based orc::MemoryMapper.Anubhab Ghosh
This is an implementation of orc::MemoryMapper that maps shared memory pages in both executor and controller process and writes directly to them avoiding transferring content over EPC. All allocations are properly deinitialized automatically on the executor side at shutdown by the ExecutorSharedMemoryMapperService. Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D128544
2022-06-21Re-apply "[JITLink][Orc] Add MemoryMapper interface with InProcess ↵Anubhab Ghosh
implementation" [JITLink][Orc] Add MemoryMapper interface with InProcess implementation MemoryMapper class takes care of cross-process and in-process address space reservation, mapping, transferring content and applying protections. Implementations of this class can support different ways to do this such as using shared memory, transferring memory contents over EPC or just mapping memory in the same process (InProcessMemoryMapper). The original patch landed with commit 6ede65205073d3cf6b1ed4d101e66eae3e0fc8e6 It was reverted temporarily in commit 6a4056ab2ada0046ff97a55a5fb34c2c59504fd1 Reviewed By: sgraenitz, lhames Differential Revision: https://reviews.llvm.org/D127491
2022-06-21Revert "[JITLink][Orc] Add MemoryMapper interface with InProcess implementation"Nico Weber
This reverts commit 6ede65205073d3cf6b1ed4d101e66eae3e0fc8e6. Doesn't build on Windows, see https://reviews.llvm.org/D127491#3598773
2022-06-21[JITLink][Orc] Add MemoryMapper interface with InProcess implementationAnubhab Ghosh
MemoryMapper class takes care of cross-process and in-process address space reservation, mapping, transferring content and applying protections. Implementations of this class can support different ways to do this such as using shared memory, transferring memory contents over EPC or just mapping memory in the same process (InProcessMemoryMapper). Reviewed By: sgraenitz, lhames Differential Revision: https://reviews.llvm.org/D127491