Changes between Version 1 and Version 2 of Commentary/Compiler/CmmType

Dec 6, 2006 7:22:43 PM (9 years ago)



  • Commentary/Compiler/CmmType

    v1 v2  
    137137 * [ A Single Intermediate Language That Supports Multiple Implementations of Exceptions (2000)] (Paper page with Abstract)
    138138 * [ The C-- Language Specification Version 2.0 (CVS Revision 1.128, 23 February 2005)] (PDF)
     140Cmm is not a stand alone C-- compiler; it is an implementation of C-- embedded in the GHC compiler.  One difference between Cmm and a C-- compiler like [ Quick C--] is this: Cmm uses the C preprocessor (cpp).  Cpp lets Cmm ''integrate'' with C code, especially the C header defines in [[GhcFile(includes)]], and among many other consequences it makes the C-- `import` and `export` statements irrelevant; in fact, according to [[GhcFile(compiler/cmm/CmmParse.y)]] they are ignored.  The most significant action taken by the Cmm modules in the Compiler is to optimise Cmm, through [[GhcFile(compiler/cmm/CmmOpt.hs)]].  The Cmm Optimiser generally runs a few simplification passes over primitive Cmm operations, inlines simple Cmm expressions that do not contain global registers (these would be left to one of the [wiki:Commentary/Compiler/Backends Backends], which currently cannot handle inlines with global registers) and performs a simple loop optimisation.
     142=== Code Blocks in Cmm ===
     143The Haskell representation of Cmm separates contiguous code into:
     144 * ''modules'' (compilation units; a `.cmm` file); and
     145 * ''basic blocks''
     147Cmm modules contain static data elements (see [wiki:Commentary/Compiler/CmmType#LiteralsandLabels Literals and Labels]) and [wiki:Commentary/Compiler/CmmType#BasicBlocks:Procedures Basic Blocks], collected together in `Cmm`, a type synonym for `GenCmm`, defined in [[GhcFile(compiler/cmm/Cmm.hs)]]:
     149newtype GenCmm d i = Cmm [GenCmmTop d i]
     151type Cmm = GenCmm CmmStatic CmmStmt
     153data GenCmmTop d i
     154  = CmmProc
     155     [d]               -- Info table, may be empty
     156     CLabel            -- Used to generate both info & entry labels
     157     [LocalReg]        -- Argument locals live on entry (C-- procedure params)
     158     [GenBasicBlock i] -- Code, may be empty.  The first block is
     159                       -- the entry point.  The order is otherwise initially
     160                       -- unimportant, but at some point the code gen will
     161                       -- fix the order.
     163                       -- the BlockId of the first block does not give rise
     164                       -- to a label.  To jump to the first block in a Proc,
     165                       -- use the appropriate CLabel.
     167  -- some static data.
     168  | CmmData Section [d] -- constant values only
     170type CmmTop = GenCmmTop CmmStatic CmmStmt
     172`CmmStmt` is described in [wiki:Commentary/Compiler/CmmType#StatementsandCalls Statements and Calls];[[BR]]
     173`Section` is described in [wiki:Commentary/Compiler/CmmType#SectionsandDirectives Sections and Directives];[[BR]]
     174the static data in `[d]` is [`CmmStatic`] from the type synonym `Cmm`;[[BR]]
     175`CmmStatic` is described in [wiki:Commentary/Compiler/CmmType#LiteralsandLabels Literals and Labels].
     177==== Basic Blocks and Procedures ====
     179Cmm procedures are represented by the first constructor in `GenCmmTop d i`:
     181    CmmProc [d] CLabel [LocalReg] [GenBasicBlock i]
     183For a description of Cmm labels and the `CLabel` data type, see the subsection [wiki:Commentary/Compiler/CmmType#LiteralsandLabels Literals and Labels], below.
     185Cmm Basic Blocks are labeled blocks of Cmm code ending in an explicit jump.  Sections (see [wiki:Commentary/Compiler/CmmType#SectionsandDirectives Sections and Directives]) have no jumps--in Cmm, Sections cannot contain nested Procedures (see, e.g., [wiki:Commentary/Compiler/CmmType#CompilingCmmwithGHC Compiling Cmm with GHC]).  In Basic Blocks represent parts of Procedures.  The data type `GenBasicBlock` and the type synonym `CmmBasicBlock` encapsulate Basic Blocks; they are defined in [[GhcFile(compiler/cmm/Cmm.hs)]]:
     187data GenBasicBlock i = BasicBlock BlockId [i]
     189type CmmBasicBlock = GenBasicBlock CmmStmt
     191newtype BlockId = BlockId Unique
     192  deriving (Eq,Ord)
     194instance Uniquable BlockId where
     195  getUnique (BlockId u) = u
     197The `BlockId` data type simply carries a `Unique` with each Basic Block.  For descriptions of `Unique`, see
     198 * the [wiki:Commentary/Compiler/Renamer Renamer] page;
     199 * the [wiki:Commentary/Compiler/WiredIn#Knownkeythings Known Key Things] section of the [wiki:Commentary/Compiler/WiredIn Wired-in and Known Key Things] page; and,
     200 * the [wiki:Commentary/Compiler/EntityTypes#Typevariablesandtermvariables Type variables and term variables] section of the [wiki:Commentary/Compiler/EntityTypes Entity Types] page.