Code Generator

This page describes code generator ("codegen") in GHC. It is meant to reflect current state of the implementation. If you notice any inaccuracies please update the page (if you know how) or complain on ghc-devs.

A brief history of code generator

You might occasionally hear about "old" and "new" code generator. GHC 7.6 and earlier used the old code generator. New code generator was being developed since 2007 and it was enabled by default on 31 August 2012 after the release of GHC 7.6.1. The first stable GHC to use the new code generator is 7.8.1 released in early 2014.

Various historical pages, with still-useful info:


Use Keyword = CodeGen to ensure that a ticket ends up on these lists.

Open Tickets:

Remove Hack in compiler/nativeGen/X86/CodeGen.hs
Avoid unnecessary evaluation when unpacking constructors
Refactor the plumbing of CafInfo to make it more robust
No-op assignment I64[BaseReg + 784] = I64[BaseReg + 784]; is generated into optimized Cmm
Double double assignment in optimized Cmm on SPARC
Add dead store elimination
Function arguments are always spilled/reloaded if scrutinee is already in WHNF
Avoid TidyPgm predicting what CorePrep will do
Cheap-to-compute values aren't pushed into case branches inducing unnecessary register pressure
Implement the 'Improved LLVM Backend' proposal
Take more advantage of STG representation invariance (follows up #9291)
LLVM does not need to trash caller-saved registers.
Common Block Elimination pass doesn't eliminate common blocks
CMM contains a bunch of tail-merging opportunities
Introduce PTR-tagging for big constructor families
No need to enter a scrutinised value
Make likelyhood of branches/conditions available throughout the compiler.
Code generator does not correctly tag a pointer
Move stack checks out of code paths that don't use the stack.
Use test instead of cmp for comparison against zero.
Only turn suitable targets into a fallthrough in CmmContFlowOpt.
Use appropriatly sized comparison instruction for small values.
Improve block layout for the NCG
Opportunity to compress common info table representation.
Allow setting of custom alignments
How untagged pointers sneak into banged fields
Invert floating point comparisons such that no extra parity check is required.
Implement CMOV support.

Closed Tickets:

LLVM codegen does not handle integer literals in branch conditionals.
Register allocator chokes on certain branches with literals
LLVM backend does not properly widen certain literal types in call expressions
Loopification should omit stack check
cmm common block not eliminated
cmm case, binary search instead of jump table
Loopification does not trigger for IO even if it could
GHC and LLVM don't agree on what to do with byteSwap16#
Improve cmm/assembly for pattern matches with two constants.
Improve assembly for dense jump tables.
CBE pass 2 invalidates proc points
Speed optimizations for elimCommonBlocks
Update JMP_TBL targets during shortcutting for x86 codegen.
Catch cases where both branches of an if jump to the same block.

Last modified 5 weeks ago Last modified on May 19, 2018 7:49:15 PM