Stream: cranelift

Topic: Multithreaded Compiler


view this post on Zulip PROMETHIA (Dec 17 2023 at 01:24):

How would y'all recommend designing a multithreaded JIT compiler using cranelift? The main issue I'm running into is JITModule, the rest seems to be fine. My issue is not so much using the JITModule itself in parallel (I'm making a lazy jit which by its nature will only ask for one function at a time) but rather that in a very threaded environment it's hard to access the JITModule since it isn't send or sync. Can't use a static variable for it, would rather have 1 instead of one per thread, and don't want to have a thread dedicated to sending and receiving things about the JITModule that other threads talk to. I'm not sure how else to go about it, unless the JITModule could be made threadsafe directly. I could also be convinced to use one of the above options but I don't currently think they're worth the effort.

view this post on Zulip bjorn3 (Dec 17 2023 at 10:45):

Should be fine to implement Send for it, I don't think making it Sync can be done then in any better way other than just wrapping it in a Mutex.

view this post on Zulip PROMETHIA (Dec 17 2023 at 14:53):

That's what I thought. I think it's just !Send because of the dyn Fn used for libcalls which doesn't have a + Send bound. I'll see about opening a PR soon if I remember


Last updated: Dec 23 2024 at 12:05 UTC