19 Commits

Author SHA1 Message Date
Lang Hames
bfc732efbd
[orc-rt] Add ControllerAccess interface. (#169598)
ControllerAccess provides an abstract interface for bidirectional RPC
between the executor (running JIT'd code) and the controller (containing
the llvm::orc::ExecutionSession). ControllerAccess implementations are
expected to implement IPC / RPC using a concrete communication method
(shared memory, pipes, sockets, native system IPC, etc).

Calls from executor to controller are made via callController, with
"handler tags" (addresses in the executor) specifying the target handler
in the controller. A handler must be associated in the controller with
the given tag for the call to succeed. This ensures that only registered
entry points in the controller can be used, and avoids leaking
controller addresses into the executor.

Calls in both directions are to "wrapper functions" that take a buffer
of bytes as input and return a buffer of bytes as output. In the ORC
runtime these must be `orc_rt_WrapperFunction`s (see
Session::handleWrapperCall). The interpretation of the byte buffers is
up to the wrapper functions: the ORC runtime imposes no restrictions on
how the bytes are to be interpreted.

ControllerAccess objects may be detached from the Session prior to
Session shutdown, in which case no further calls may be made in either
direction, and any pending results (from calls made that haven't
returned yet) should return errors. If the ControllerAccess class is
still attached at Session shutdown time it will be detached as part of
the shutdown process. The ControllerAccess::disconnect method must
support concurrent entry on multiple threads, and all callers must block
until they can guarantee that no further calls will be received or
accepted.
2025-11-26 14:53:00 +11:00
Lang Hames
ea9ec7cfb5
[orc-rt] Rename 'Session' variables to avoid ambiguity with type. NFCI. (#168999)
Re-using Session as a variable name risks confusion with the Session
type.
2025-11-21 18:01:23 +11:00
Lang Hames
be1a504228
[orc-rt] Simplify Session shutdown. (#168664)
Moves all Session member variables dedicated to shutdown into a new
ShutdownInfo struct, and uses the presence / absence of this struct as
the flag to indicate that we've entered the "shutting down" state. This
simplifies the implementation of the shutdown process.
2025-11-19 16:36:30 +11:00
Lang Hames
411c75210e [orc-rt] Fix typos in file comments. 2025-11-19 11:19:46 +11:00
Lang Hames
ed78ab7ca0
[orc-rt] Introduce Task and TaskDispatcher APIs and implementations. (#168514)
Introduces the Task and TaskDispatcher interfaces (TaskDispatcher.h),
ThreadPoolTaskDispatcher implementation (ThreadPoolTaskDispatch.h), and
updates Session to include a TaskDispatcher instance that can be used to
run tasks.

TaskDispatcher's introduction is motivated by the need to handle calls
to JIT'd code initiated from the controller process: Incoming calls will
be wrapped in Tasks and dispatched. Session shutdown will wait on
TaskDispatcher shutdown, ensuring that all Tasks are run or destroyed
prior to the Session being destroyed.
2025-11-19 09:50:46 +11:00
Lang Hames
4c4b1a905e
[orc-rt] Replace wrapper fn void *CallCtx arg with uint64_t CallId. (#167452)
This argument serves as an opaque id (outside the ControllerAccess
object) for a call to a wrapper function. I expect that most
ControllerAccess implementations will want to use this argument as a
sequence number (plain integer), for which uint64_t will be a better fit
than void*. For ControllerAccess implementations that want to use a
pointer, uint64_t should be sufficiently large.
2025-11-11 18:11:41 +11:00
Lang Hames
2ba960c404 [orc-rt] Rename InitializeRequest variables after 7381558ef8b. NFCI.
7381558ef8b renamed the FinalizeRequest type to InitializeRequest. This commit
updates InitializeRequest variable names to follow suit ("FR"s become "IR"s).
2025-10-13 20:21:05 +11:00
Lang Hames
7381558ef8
[orc-rt] Rename SimpleNativeMemoryMap finalize & deallocate. NFCI. (#163114)
This commit renames the "finalize" operation to "initialize", and
"deallocate" to "deinitialize".

The new names are chosen to better fit the point of view of the
ORC-runtime and executor-process: After memory is *reserved* it can be
*initialized* with some content, and *deinitialized* to return that
memory to the reserved region.

This seems more understandable to me than the original scheme, which
named these operations after the controller-side JITLinkMemoryManager
operations that they partially implemented. I.e.
SimpleNativeMemoryMap::finalize implemented the final step of
JITLinkMemoryManager::finalize, initializing the memory in the executor;
and SimpleNativeMemoryMap::deallocate implemented the final step of
JITLinkMemoryManager::deallocate, running dealloc actions and releasing
the finalized region.

The proper way to think of the relationship between these operations now
is that:

1. The final step of finalization is to initialize the memory in the
executor.

2. The final step of deallocation is to deinitialize the memory in the
executor.
2025-10-13 12:33:16 +11:00
Lang Hames
d4a4137976
[orc-rt] Add multi-addr dealloc/release to SimpleNativeMemoryMap. (#163025)
In an ORC JIT it's common for multiple memory regions to be deallocated
at once, e.g. when a ResourceTracker covering multiple object files is
removed. This commit adds SimpleNativeMemoryMap::deallocateMultiple and
SimpleNativeMemoryMap::releaseMultiple APIs that can be used to reduce
the number of calls (and consequently IPC messages in cross-process
setups) in these cases.

Adding these operations will make it easier to write an
llvm::orc::MemoryMapper class that can use SimpleNativeMemoryMap as a
backend.
2025-10-12 12:03:11 +11:00
Lang Hames
27e2d5c46f
[orc-rt] Align SimpleNativeMemoryMap Segment with LLVM type. (#162823)
This commit aims to align SimpleNativeMemoryMap::FinalizeRequest::Segment with
llvm::orc::tpctypes::SegFinalizeRequest. This will simplify construction of a
new LLVM JITLinkMemoryManager that's capable of using SimpleNativeMemoryMap as
a backend.
2025-10-11 10:33:28 +11:00
Lang Hames
822446d74a [orc-rt] Remove (effectively) unused header orc-rt-c/orc-rt.h. NFCI.
This header was a placeholder in the initial project check-in, but is not used.
Time to remove it.
2025-10-09 14:32:31 +11:00
Lang Hames
ab7138154b
[orc-rt] Add Session class. (#162590)
An orc-rt Session contains a JIT'd program, managing resources and
communicating with a remote JIT-controller instance (expected to be an
orc::ExecutionSession, though this is not required).
2025-10-09 14:27:10 +11:00
Lang Hames
891f002026
[orc-rt] Add SimpleNativeMemoryMap. (#162584)
SimpleNativeMemoryMap is a memory allocation backend for use with ORC.
It can...

1. Reserve slabs of address space.
2. Finalize regions of memory within a reserved slab: copying content
into requested addresses, applying memory protections, running
finalization actions, and storing deallocation actions to be run by
deallocate.
3. Deallocate finalized memory regions: running deallocate actions and,
if possible, making memory in these regions available for use by future
finalization operations. (Some systems prohibit reuse of executable
memory. On these systems deallocated memory is no longer usable within
the process).
4. Release reserved slabs. This runs deallocate for any
not-yet-deallocated finalized regions, and then (if possible) returns
the address space to system. (On systems that prohibit reuse of
executable memory parts of the released address space may be permanently
unusable by the process).

SimpleNativeMemoryMap is intended primarily for use by
llvm::orc::JITLinkMemoryManager implementations to allocate JIT'd code
and data.
2025-10-09 13:10:34 +11:00
Lang Hames
deef49e472 [orc-rt] Add ResourceManager interface.
The ResourceManager interface can be used to implement ownership for resources
allocated to JIT'd code, e.g. memory and metadata registrations (frame info,
language runtime metadata, etc.).

Resources can be *deallocated*, meaning that they should be cleaned up (memory
released, registrations deregistered, etc.), or they can be *detached*, meaning
that cleanup should be performed automatically when the ResourceManager itself
is destroyed.

The intent is to allow JIT'd code to continue running after the
llvm::orc::ExecutionSession that produced it is disconnected / destroyed.
2025-10-09 11:58:40 +11:00
Lang Hames
88a5429a8c
[orc-rt] Add allocation-action execution support. (#157244)
This commit contains executor-side support for ORC allocation actions
(see e50aea58d59).

An AllocAction is a function pointer with type
orc_rt_WrapperFunctionBuffer (*)(const char *ArgData, size_t ArgSize),
along with an associated blob of argument bytes.

An AllocActionPair is a pair of AllocActions, one to be run at memory
finalization time and another to be run at deallocation time.

The runFinalizeActions function can be used to run all non-null finalize
actions in a sequence of AllocActionPairs, returning the corresponding
sequence of deallocation actions on success.

The runDeallocActions function can be used to run a sequence of dealloc
actions returned by runFinalizeActions.
2025-09-07 11:09:28 +10:00
Lang Hames
9697b3c7d3
[orc-rt] Fix file comment in RTTI.cpp. NFC. (#155059) 2025-08-23 12:47:56 +10:00
Lang Hames
6df9a13e40
[orc-rt] Use LLVM-style header naming scheme. (#154881)
This is more consistent with the rest of the LLVM project, and the
resulting names are closer to the types defined in each of the headers.
2025-08-22 14:28:02 +10:00
Lang Hames
9039b591d0 [orc-rt] Add rtti header and unit tests.
The orc-rt extensible RTTI mechanism is used to provide simple dynamic RTTI
checks for orc-rt types that do not depend on standard C++ RTTI (meaning that
they will work equally well for programs compiled with -fno-rtti).
2025-08-21 18:59:46 +10:00
Lang Hames
ee7a6a45bd
[ORC-RT] Initial check-in for a new, top-level ORC runtime project. (#113499)
Includes CMake files and placeholder header, library, test tool, regression
test and unit test.

The aim for this project is to create a replacement for the existing ORC
Runtime that currently resides in `llvm-project/compiler-rt/lib/orc`. The new
project will provide a superset of the original features, and the old runtime
will be removed once the new runtime is sufficiently developed.

See discussion at
https://discourse.llvm.org/t/rfc-move-orc-executor-support-into-top-level-project/81049
2025-08-19 10:56:18 +10:00