[LLVMdev] Adding safe-point code generation

Nicolas Geoffray nicolas.geoffray at lip6.fr
Mon Jun 22 00:57:35 PDT 2009

Hi Jeffrey,

Jeffrey Yasskin wrote:
> 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.

That's great!

> 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.

Agree. I guess, a flag on a function saying that GC/Thread points have 
already been inserted would make it.

> 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.

I don't think that's worth the pain, if it's only to avoid duplicated 
safe points.

> 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.

I like this one. I think that's the best way to go. The safe points 
"pass" in the GC already computes the safe points (except for "for 
loops") , so we've got a base. I don't think llvm.safepoint needs to be 
a function, a function pass could replace the intrinsic with instructions.

Thanks for working on this!


> Thoughts?
> Thanks,
> Jeffrey
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

More information about the llvm-dev mailing list