1

I've been writing a toy language for LLVM. The most ambitious feature I want to implement is fibers. I've read much about the matter, and I think I have a vague idea of how they are traditionally implemented. As far as I can tell, fibers are usually modeled as an instruction pointer and a stack. (See: the Golang runtime)

Is there any LLVM support for asynchronous execution, with different instruction pointers? Multiple stacks?

I'm aware that LLVM is a register machine, is there any way to ensure that all the relevant data is saved on the stack? And/or a way to save and restore the current register state?

Implementing this by hand would be a real pest, so any help is appreciated!

Others
  • 2,876
  • 2
  • 30
  • 52
  • The question about saving/restoring register state is an interesting one. It probably deserves it's own question though. – Jackson Loper Nov 12 '15 at 22:12

1 Answers1

0

For a toy language, one quick solution is to simulate the behavior of fibers using threads. Make a bunch of threads, but ensure that only one of them is doing anything. You can make the other threads chill out by telling them to make a blocking call to a socket connected to the main thread.

Obviously, threads are more expensive than fibers. So this will not be ideal, performance-wise.

If you want performance, unfortunately, as far as I know, the only way is to manage the front-end stack explicitly, all by yourself. For example, one approach is to

The "continuation" objects then fulfill the role of instruction pointers (although in a very different way!), and your hand-allocated memory fulfills the role of the stack data. More details can be found here.

Jackson Loper
  • 525
  • 4
  • 10