[LLVMdev] Adding safe-point code generation
Jeffrey Yasskin
jyasskin at google.com
Sun Jun 21 22:49:08 PDT 2009
Hi all,
I need to add thread-switching support to Unladen Swallow's JIT, and
LLVM's safe point support looks like a good way to get code into all
the right places. However,
http://llvm.org/docs/GarbageCollection.html#collector-algos points out
that there's no way to emit code at safe points yet, and there are no
loop safe points at all. So I'll be trying to implement them.
Is there anything I should know before starting?
One way to do this might be to add a FunctionPass to
LLVMTargetMachine::addCommonCodeGenPasses() alongside
createGCLoweringPass(), which would insert user-defined code for safe
points. Unfortunately, code inserted there would stick around in the
IR after the machine code was emitted, and if the function were JITted
again, we'd get duplicate safe points.
Another way to do it might be to add a MachineFunction pass next to
createGCMachineCodeAnalysisPass() (or instead of it), which could emit
appropriate MachineInstructions to implement the safe point. This, of
course, forces safe points to be written in MachineInstructions
instead of IR instructions, which isn't ideal.
Another way might be to run a pass over the IR inserting
llvm.safepoint() calls, which could be implemented as a function in
the module. Then we'd want a MachineFunction pass to inline this for
us during codegen. The llvm.safepoint() calls could be easily
identified and removed if the IR needs to be re-used.
Thoughts?
Thanks,
Jeffrey
More information about the llvm-dev
mailing list