Stream: cranelift

Topic: PHP interpreter/JIT using Cranelift?


view this post on Zulip JP Barringer (Sep 06 2025 at 13:49):

I'm currently working on this. PHP -> AST -> CLIF -> [Pulley / Cranelift / Cranelift interpreter]
And considering a more complex version: PHP -> AST -> MLIR dialect -> MLIR -> CLIF -> ...

I'm working through some of the PHP fundamentals but I'm curious if anyone here has thoughts on the feasibility of this approach and/or ideas about gotchas or how to do this well. Is Cranelift potentially a good fit?

view this post on Zulip Chris Fallin (Sep 07 2025 at 23:58):

Sure, Cranelift should be usable as a backend; of course the hard part is going to be the "JIT for a dynamic language" part, not the codegen library/compiler backend that you choose :-)

There are some kinds of things that JITs want to do for dynamism that, if your implementation becomes advanced enough, you'll have to find your way around in: for example, ICs and on-stack replacement (tiering up or tiering down, sometimes called "deopt" in that direction). One could do ICs with function pointers and indirect calls (so dynamic updates are just data updates); replacing stack frames is trickier but I have some vague thoughts how this could eventually work.

I'm not sure about the pathway through MLIR that you describe -- at a glance at least, that seems unnecessarily complex, unless there's some other attraction to it (e.g., pre-existing frontend or PHP-specific dialect+optimizations or...)

view this post on Zulip JP Barringer (Sep 08 2025 at 14:01):

Thanks. Yeah I'm definitely running before I can walk here. This whole question started with a PHP interpreter, with JIT op as a tier 2 feature. Trying to figure out some architectural choices ahead of time to keep that path open. The idea was to use a common MIR for both the interpreter and JIT (with the Cranelift interpreter in mind – although now I'm less sure of that approach).

MLIR is a bit of a side quest. The question is, if this already is looking like PHP -> HIR -> CLIF then "what if the HIR is a PHP MLIR dialect?" This might open up some paths to other backends for AOT (notably MLIR -> LLVM) further down the road.


Last updated: Dec 06 2025 at 07:03 UTC