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

Kenneth Uildriks kennethuil at gmail.com
Sat Apr 10 14:34:15 PDT 2010

On the other hand, stack manipulation really ought to be handled by
the target, since only the target knows the details of how the stack
is laid out to begin with.  Also, if we have stack manipulation calls
in the IR, optimization quickly becomes very difficult.  Unless we
just allow optimizers to ignore the stack manipulations and assume
they're doing the "right" thing.

On the gripping hand, we don't want the target emitting memory
allocation calls in order to grow the stack (unless a function pointer
to malloc or its equivalent is passed in from the IR).

> The way they accomplish that now is by
> copying the entire stack to the heap on a context switch, and having
> all threads share the main C stack. This isn't quite as bad as it
> sounds because it only happens to threads that call into C extension
> modules. Pure Python threads operate entirely within heap Python
> frames. Still, it would be nice to support this use case.

This wouldn't hold in IR, since virtual registers regularly get
spilled to the stack.. every context, regardless of the language,
would have to have its stack saved.  Also, this method would mean that
a context cannot be used in any native thread other than the one that
created it, right?

More information about the llvm-dev mailing list