jaguar is a project aiming at adding asynchronous support to the
The official repository is located here.
The project has been done for the PRPA class, (parallel programming). The code
we want to achieve at the end is something similar to this:
The following grammar changes have been made:
These changes allow usage of the following code:
The implementation has been done at the
LLVM IR level, in the
Tiger Compiler (TC-L).
The perfect usage of LLVM would be to use it as an external library, and
provide a non-intrusive usage for our front-end.
But, we can’t use
LLVM IR in order to lower the calls, since we need to do
some target-specific operations, like
push, regarding the calling convention.
First, we’ll need a
MachineFunctionPass, which allows us to use
MachineInstrs in order to modify the current function, so to implement the
The problem is that we can’t load a
MachineFunctionPass as a dynamic pass,
as we can do with a
FunctionPass, so, we need to modify the X86 backend.
The repository containing the modified
LLVM implementation is
The approach we took for an asynchronous task is the following:
- Spawn a new
POSIX thread (
- Keep track of the handle of the thread.
- Join the thread when the result of the function is used.
Let’s take an example of an use-case of the async call.
So, the following routines have been added to the runtime:
First, added to the C runtime:
then, the rest of it added to the
LLVM IR runtime:
Another solution is to provide a thread pool in Tiger’s runtime, available
using compiler intrinsics, translated during
The best solution is to handle the routines as resumable routines.
This means that the routines can be paused, the context saved, and replaced
with another routine, etc.
This implies that the routines should contain some kind of context, some kind
of state that allows the compiler to define where to resume.