[Haskell-cafe] Compiler backend question
ndmitchell at gmail.com
Tue Jan 1 08:37:23 EST 2008
> If I understand it correctly, the GHC compiler either directly generates
> machinecode, or it uses C as an intermediate language.
> I also read somewhere that C is not the most efficient intermediate
> representation for functional languages, and that one gets better
> performance when generating native machine code.
> However, from the discussions in this list, I could conclude that the low
> level machine code optimizer of GHC is far from state-of-the-art compared to
> industry standard C/C++ compilers.
These all seem fair comments, based on my understanding. One other
thing to remember is that the GHC people know this, and much work has
been done, and will continue to be done until the back end is up to
the standard of the front end.
> I was wondering, why doesn't GHC use the GCC (or any other standard
> compiler) backend intermediate code? The backend of GCC generates highly
> optimized code no? Or is the intermediate code format of GCC (or other
> compilers) not suitable for Haskell?
GCC is optimised for dealing with code that comes from C, and the back
end language is much like C. GCC is also not really set up to be used
by bolting different front ends on to different back ends - part of
this is a license issue - if the front and back ends were well split
and available separately you could write a commerical backend onto a
GPL front end.
> Another question regarding the backend: a cool feature of the Microsoft
> Visual C++ (MVC) compiler is its ability to perform "LTCG"
> (link-time-code-generation), performing whole program optimization. It
> something like this possible with Haskell / (or the GCC backend?). Would it
> be possible to feed all the generated C code of the GHC compiler into the
> MVC compiler, to generate one big MVC / LTCG generated executable? It would
> be interesting to see how much the whole program optimization approach
> (which can do analysis on the program as if it was a single module) would
> improve performance...
You would get much better improvements on whole program at the Haskell
level. By the time you get to the generated C you have obfustcated all
the structure of the program, and are unlikely to benefit that much.
More information about the Haskell-Cafe