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

Kenneth Uildriks kennethuil at gmail.com
Sun Apr 11 16:23:07 PDT 2010


>>
>>> 2. We should be able to support "hard switching" in Stackless Python
>>> by adding a llvm.getcontextstacktop intrinsic.  If, as in Kristján's
>>> example, llvm.getcontext is used to create context A, and then
>>> execution continues until context B is created with
>>> llvm.swapcontext(B, A), the region of memory between
>>> llvm.getcontextstacktop(A) and llvm.getcontextstacktop(B) can be saved
>>> and later restored when B is resumed.
>>
>> Wait, what stack top does swapcontext get? I'd thought that A's and
>> B's stack top would be the same since they're executing on the same
>> stack.
>
> No, A's stack top would be whatever the stack pointer was when
> llvm.getcontext was called to
> create it.  B's stack top would be whatever the stack pointer was when
> llvm.swapcontext was
> called to create it... it would be further from the common base than
> A's stack top.  The region
> between them is what needs to be restored before B can become active
> again, assuming that
> A's stack space remained valid.

I forgot to mention that this depends on the assumption that the
function that created context A did not return to its caller before
the llvm.swapcontext that created context B was executed.  And while
I'm at it, what it the function that created context A made a tail
call in the meantime?




More information about the llvm-dev mailing list