Code generation options in haskell

Hello, i have submitted a custom GSoC proposal for improving cmm code generation in GHC. Cmm is an IR that gets compiled to native code directly or through LLVM. It is targeted by STG, an earlier GHC IR.

I am wondering if there are other code generation options in haskell ( or a language with particularly good interop, i think agda fits) .
Apparently a few people have implemented ANF based code generators, but i havent found them. There are various llvm libraries, although they are individually not that active. Am i missng something else ? Like is there some library to target another IR, or like targetting C code ? ( cmm technically can , but this is outdated )

I think the C backend of GHC should still be stable. There are a some packages that do their own code generation such as accelerate which generates LLVM using the llvm-pretty package (or at least I heard they were looking to switch to that).

3 Likes

Their github paga says “Currently, llvm-pretty supports LLVM versions up through 17” . LLVM is already on version 20.

Thanks for pointing the c backend of cmm. It may have a reusable c AST and pretty printer. But currently the C GHC backend itself is not desirable since it can produce either slow portable code or code that depends on unstable gcc features.

Speaking of which : i opened a thread to see if that can be fixed : Can the following llvm IR features be emulated in clang or gcc? - Using Clang - LLVM Discussion Forums

LLVM is often backwards compatible, so you might still be able to use it. And you can always add missing features yourself. It was not that hard when I did it for my master’s thesis: More visibility and linkage by noughtmare · Pull Request #78 · GaloisInc/llvm-pretty · GitHub.

Ah, I didn’t know you cared about performance. What do you actually want to do with alternative code generators?

1 Like

The custom GSoC proposal i formulated is about either upgrading and updating the llvm backend for cmm ( the code generation part of GHC ). Or introducing an improved register allocator for the code generator that directly takes cmm.

However i was also wondering if i could improve the c code generator to produce fast code that would work both on clang and gcc and across versions