[LLVMdev] Proposal: stack/context switching within a thread

Jeffrey Yasskin jyasskin at google.com
Fri Apr 16 19:30:10 PDT 2010

On Sun, Apr 11, 2010 at 10:07 PM, Jeffrey Yasskin <jyasskin at google.com> wrote:
> I'll forward your next draft back to the stackless folks, unless you
> want to pick up the thread with them.

Their reply: http://thread.gmane.org/gmane.comp.python.stackless/4464/focus=4475

Instead of @llvm.getcontextstacktop(%context), they want
@llvm.getcurrentstacktop() so that they can copy the stack out before
switching, and copy it back in after switching. I'm not sure this
exactly works either, since before "copying the stack back", any
allocas are pointing at old-frame data and so are invalid. They'd need
to guarantee that any relevant data is in machine registers rather
than the stack during the switch, but LLVM doesn't provide a way to do
that. The cleaner way to do this is to switch to an intermediate stack
scheduler context with its own stack, have it replace the stacks, and
then switch to the target context back on the original stack. But that
requires two swapcontext() calls, which seems less than idea

Since the backend _can_ ensure that the relevant data is in machine
registers, do you think it makes sense to provide a swapcontext() that
also moves the stack? Or is there another way to do this that I'm


More information about the llvm-dev mailing list