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


Ignore:
Timestamp:
Dec 6, 2006 7:22:43 PM (7 years ago)
Author:
p_tanski
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/Compiler/CmmType

    v1 v2  
    137137 * [http://cminusminus.org/abstracts/c--pldi-00.html A Single Intermediate Language That Supports Multiple Implementations of Exceptions (2000)] (Paper page with Abstract) 
    138138 * [http://cminusminus.org/extern/man2.pdf The C-- Language Specification Version 2.0 (CVS Revision 1.128, 23 February 2005)] (PDF) 
     139 
     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 [http://cminusminus.org/code.html 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.  
     141 
     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'' 
     146 
     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)]]: 
     148{{{ 
     149newtype GenCmm d i = Cmm [GenCmmTop d i] 
     150  
     151type Cmm = GenCmm CmmStatic CmmStmt 
     152 
     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. 
     162 
     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. 
     166 
     167  -- some static data. 
     168  | CmmData Section [d] -- constant values only 
     169 
     170type CmmTop = GenCmmTop CmmStatic CmmStmt 
     171}}} 
     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]. 
     176 
     177==== Basic Blocks and Procedures ==== 
     178 
     179Cmm procedures are represented by the first constructor in `GenCmmTop d i`: 
     180{{{ 
     181    CmmProc [d] CLabel [LocalReg] [GenBasicBlock i] 
     182}}} 
     183For a description of Cmm labels and the `CLabel` data type, see the subsection [wiki:Commentary/Compiler/CmmType#LiteralsandLabels Literals and Labels], below. 
     184 
     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)]]: 
     186{{{ 
     187data GenBasicBlock i = BasicBlock BlockId [i] 
     188 
     189type CmmBasicBlock = GenBasicBlock CmmStmt 
     190 
     191newtype BlockId = BlockId Unique 
     192  deriving (Eq,Ord) 
     193 
     194instance Uniquable BlockId where 
     195  getUnique (BlockId u) = u 
     196}}} 
     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. 
     201