# The Glasgow Haskell Compiler and LLVM

DevFeed: [The Glasgow Haskell Compiler and LLVM](<https://devfeed.tech/articles/the-glasgow-haskell-compiler-and-llvm-42851.md>)

Original publisher: [Read original article](<https://blog.llvm.org/2010/05/glasgow-haskell-compiler-and-llvm.html>)

Author: David Terei

Published: 2010-05-17T21:19:00Z

Content type: article

Language: en

Sources: [LLVM Project](<https://devfeed.tech/sources/the-llvm-project-blog.md>)

Topics: [Haskell](<https://devfeed.tech/topics/haskell.md>), [LLVM](<https://devfeed.tech/topics/llvm.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [Functional programming](<https://devfeed.tech/topics/functional-programming.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Code generation](<https://devfeed.tech/topics/code-generation.md>), [Linux](<https://devfeed.tech/topics/linux.md>), [x86](<https://devfeed.tech/topics/x86.md>)

Tags: [code-generator](<https://devfeed.tech/tags/code-generator.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [functional-programming](<https://devfeed.tech/tags/functional-programming.md>), [ghc](<https://devfeed.tech/tags/ghc.md>), [haskell](<https://devfeed.tech/tags/haskell.md>), [linux](<https://devfeed.tech/tags/linux.md>), [llvm](<https://devfeed.tech/tags/llvm.md>), [llvm-users](<https://devfeed.tech/tags/llvm-users.md>), [new-in-llvm-2-7](<https://devfeed.tech/tags/new-in-llvm-2-7.md>), [x86](<https://devfeed.tech/tags/x86.md>)

## AI overview

This article describes the LLVM backend for the Glasgow Haskell Compiler, including its design, current Linux x86 support, existing compiler backends, and expected maintenance and optimization benefits.

## Source excerpt

If you read the LLVM 2.7 release notes carefully you would have noticed that one of the new external users is the Glasgow Haskell Compiler (GHC). As the author of the LLVM backend for GHC, I have been invited to write a post detailing the design of the backend and my experiences with using LLVM. This is that post :). I began work on the backend around July last year, undertaking it as part of an honours thesis for my bachelor of Computer Science. Currently the backend is quite stable and capable on Linux x86, able to bootstrap GHC itself. Other platforms haven't received any attention yet. What is GHC and Haskell GHC is a compiler for Haskell, a standardized, lazy, functional programming language. Haskell supports features such as static typing with type inference, lazy evaluation, pattern matching, list comprehension, type classes and type polymorphism. GHC is the most popular Haskell compiler, it compiles Haskell to native code and is supported of X86, PowerPC and SPARC. Existing pipelineBefore the LLVM backend was added, GHC already supported two backends, a C code generator and a native code generator (NCG). The C code generator was the first backend implemented and it works pretty well but is slow and fragile due to its use of many GCC specific extensions and need to post processes the assembly code produced by GCC to implement optimisations which aren't possible to do in the C code. The native code generator was started later to avoid these problems. It is around 2-3x quicker than the C backend and generally reduces the runtime of a Haskell program by around 5%. GHC developers are hoping to depreciate the C backend in the next major release. Why an LLVM backend? Offload work: Building a high performance compiler backend is a huge amount of work, LLVM for example was started around 10 years ago. Going forward, the LLVM backend should be a lot less work to maintain and extend than either the C backend or NCG. It will also benefit from any future improvements to