Version 9 (modified by guest, 9 years ago) (diff)

link in register allocator page

Native Code Generator (NCG)

For other information related to this page, see:

Overview: Files, Parts


  • compiler/nativeGen/AsmCodeGen.lhs

  • compiler/nativeGen/MachCodeGen.hs

  • compiler/nativeGen/MachInstrs.hs

  • compiler/nativeGen/NCGMonad.hs

  • compiler/nativeGen/PositionIndependentCode.hs

  • compiler/nativeGen/PprMach.hs

  • compiler/nativeGen/RegAllocInfo.hs

  • compiler/nativeGen/RegisterAlloc.hs
    one of the most complicated modules in the NCG, RegisterAlloc manages the allocation of registers for each basic block of Haskell-abstracted assembler code: management involves liveness analysis, allocation or deletion of temporary registers, spilling temporary values to the spill stack (memory) and many optimisations. See The Cmm language for the definition of a basic block (in Haskell, type CmmBasicBlock = GenBasicBlock CmmStmt).

and one header file:

  • compiler/nativeGen/NCG.h

The NCG has machine-independent and machine-dependent parts.

The machine-independent parts relate to generic operations, especially optimisations, on Cmm code. The main machine-independent parts begin with Cmm blocks. (A Cmm block is a compilation unit of Cmm code, a file. See The Cmm language for a discussion of what a Cmm block is but note that Cmm is a type synonym for GenCmmTop CmmStatic CmmStmt.) A machine-specific (assembler) instruction is represented as a Instr. The machine-independent NCG parts:


  2. lazily convert each Cmm block to abstract machine instructions (Instr) operating on an infinite number of registers--since the NCG Haskell files only contain instructions for the host computer on which GHC was compiled, these Instr are machine-specific; and,

  3. lazily allocate real registers for each basic block, based on the number of available registers on the target (currently, only the host) machine; for example, 32 integer and 32 floating-point registers on the PowerPC architecture. The NCG does not currently have support for SIMD registers such as the vector registers for Altivec or any variation of SSE.

The machine-dependent parts:

  1. define the abstract (Haskell) assembler Instr for the target (host) machine and convert every Cmm block into it;
  2. define, manage and allocate the real registers available on the target system;
  3. pretty-print the Haskell-assembler to GNU AS (GAS) assembler code