ircmaxell / php-compiler

A compiler. For PHP
MIT License
794 stars 33 forks source link

LLVM? #11

Closed driusan closed 5 years ago

driusan commented 5 years ago

From the README it seems that this project is based on gccjit. I'm not sure if this is the right place to ask, but I'm curious why that approach was taken instead of mapping the language semantics to LLVM IR and using an LLVM-based JIT. (It seems to me that LLVM IR is more mature and has more documentation available online which make it slightly more approachable.)

ircmaxell commented 5 years ago

That's exactly the direction the project has moved in the past few weeks. I need to update the readme, but the code is 95% ported to LLVM today :)

As far as why u chose libgccjit in the first place, it was mainly due to LLVM being quite daunting and libgccjit having way better docs. But looking at performance and error handling, it is clear that LLVM is the way forward.

driusan commented 5 years ago

In that case, is the project still going: AST -> Opcodes -> LLVM IR or does it go directly AST -> LLVM IR? The main benefit I see of going through the opcode step is that it's easier to do a jit, but with PHP adding its own jit the aot compilation seems to be the main benefit of this project.

Also, is there a list of low-hanging fruit that someone can try tackling to help with this project? (Related to #9, I guess)

ircmaxell commented 5 years ago

So, definitely open for discussion, but I do believe that it should still target a VM first (so include an opcode step). This is primarily due to my suspicion that there's going to be a lot of code that while is possible to compile AOT, will not be efficient. So for those cases, a VM with a JIT compiler would work best I think... And if we can re-use said JIT without the runtime type info to AOT, then that seems the best of both worlds...

As far as low-hanging fruit, some of what you've been doing definitely counts. I do want to add some documentation around stdlib and extensions, so that others can start there.

driusan commented 5 years ago

That makes sense to me.. (it's also easier to test with bin/vm.php, since from what I can tell your php-llvm package has very specific LLVM version requirements and needs either LLVM4 or LLVM9.)

ircmaxell commented 5 years ago

For now it's LLVM4, but it's on my list to target 4, 6, 8 and 9, and auto-select between them at runtime based on what .so files it can find.

I'll open an issue there for that.