[project @ 2004-08-13 10:45:16 by simonmar]
[ghc-hetmet.git] / ghc / compiler / absCSyn / AbsCSyn.lhs
index 36d3db7..3c8a470 100644 (file)
@@ -1,7 +1,7 @@
 %
 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
 %
-% $Id: AbsCSyn.lhs,v 1.46 2002/03/02 18:02:30 sof Exp $
+% $Id: AbsCSyn.lhs,v 1.56 2003/11/17 14:47:53 simonmar Exp $
 %
 \section[AbstractC]{Abstract C: the last stop before machine code}
 
@@ -14,27 +14,7 @@ From @AbstractC@, one may convert to real C (for portability) or to
 raw assembler/machine code.
 
 \begin{code}
-module AbsCSyn {- (
-       -- export everything
-       AbstractC(..),
-       C_SRT(..)
-       CStmtMacro(..),
-       CExprMacro(..),
-       CAddrMode(..),
-       ReturnInfo(..),
-       mkAbstractCs, mkAbsCStmts, mkAlgAltsCSwitch,
-       mkIntCLit,
-       mkAbsCStmtList,
-       mkCCostCentre,
-
-       -- RegRelatives
-       RegRelative(..),
-
-       -- registers
-       MagicId(..), node, infoptr,
-       isVolatileReg,
-       CostRes(Cost)
-    )-} where
+module AbsCSyn where   -- export everything
 
 #include "HsVersions.h"
 
@@ -51,17 +31,15 @@ import MachOp               ( MachOp(..) )
 import Unique           ( Unique )
 import StgSyn          ( StgOp )
 import TyCon           ( TyCon )
-import BitSet                          -- for liveness masks
+import Bitmap          ( Bitmap, mAX_SMALL_BITMAP_SIZE )
+import SMRep           ( StgWord, StgHalfWord )
 import FastTypes
-
-import Outputable
+import FastString
 \end{code}
 
 @AbstractC@ is a list of Abstract~C statements, but the data structure
 is tree-ish, for easier and more efficient putting-together.
 \begin{code}
-absCNop = AbsCNop
-
 data AbstractC
   = AbsCNop
   | AbsCStmts          AbstractC AbstractC
@@ -174,8 +152,8 @@ stored in a mixed type location.)
 
   -- see the notes about these next few; they follow below...
   | CMacroStmt         CStmtMacro      [CAddrMode]
-  | CCallProfCtrMacro  FAST_STRING     [CAddrMode]
-  | CCallProfCCMacro   FAST_STRING     [CAddrMode]
+  | CCallProfCtrMacro  FastString      [CAddrMode]
+  | CCallProfCCMacro   FastString      [CAddrMode]
 
     {- The presence of this constructor is a makeshift solution;
        it being used to work around a gcc-related problem of
@@ -192,6 +170,7 @@ stored in a mixed type location.)
   -- *** the next three [or so...] are DATA (those above are CODE) ***
 
   | CStaticClosure
+       CLabel                  -- The closure's label
        ClosureInfo             -- Todo: maybe info_lbl & closure_lbl instead?
        CAddrMode               -- cost centre identifier to place in closure
        [CAddrMode]             -- free vars; ptrs, then non-ptrs.
@@ -199,18 +178,19 @@ stored in a mixed type location.)
   | CSRT CLabel [CLabel]       -- SRT declarations: basically an array of 
                                -- pointers to static closures.
   
-  | CBitmap CLabel LivenessMask        -- A bitmap to be emitted if and only if
-                               -- it is larger than a target machine word.
+  | CBitmap Liveness           -- A "large" bitmap to be emitted
+
+  | CSRTDesc                   -- A "large" SRT descriptor (one that doesn't
+                               -- fit into the half-word bitmap in the itbl).
+       !CLabel                 -- Label for this SRT descriptor
+       !CLabel                 -- Pointer to the SRT
+       !Int                    -- Offset within the SRT
+       !Int                    -- Length
+       !Bitmap                 -- Bitmap
 
   | CClosureInfoAndCode
        ClosureInfo             -- Explains placement and layout of closure
-       AbstractC               -- Slow entry point code
-       (Maybe AbstractC)
-                               -- Fast entry point code, if any
-       String                  -- Closure description; NB we can't get this
-                               -- from ClosureInfo, because the latter refers 
-                               -- to the *right* hand side of a defn, whereas
-                               -- the  "description" refers to *left* hand side
+       AbstractC               -- Entry point code
 
   | CRetVector                 -- A labelled block of static data
        CLabel
@@ -222,7 +202,8 @@ stored in a mixed type location.)
        TyCon                   -- which TyCon this table is for
 
   | CModuleInitBlock           -- module initialisation block
-       CLabel                  -- label for init block
+       CLabel                  -- "plain" label for init block
+       CLabel                  -- label for init block (with ver + way info)
        AbstractC               -- initialisation code
 
   | CCostCentreDecl            -- A cost centre *declaration*
@@ -241,7 +222,7 @@ stored in a mixed type location.)
 -- we add a label for the table, and expect only the 'offset/length' form
 
 data C_SRT = NoC_SRT
-          | C_SRT CLabel !Int{-offset-} !Int{-length-}
+          | C_SRT !CLabel !Int{-offset-} !StgHalfWord{-bitmap or escape-}
 
 needsSRT :: C_SRT -> Bool
 needsSRT NoC_SRT       = False
@@ -260,14 +241,10 @@ macros.  An example is @STK_CHK@, which checks for stack-space
 overflow.  This enumeration type lists all such macros:
 \begin{code}
 data CStmtMacro
-  = ARGS_CHK                           -- arg satisfaction check
-  | ARGS_CHK_LOAD_NODE                 -- arg check for top-level functions
-  | UPD_CAF                            -- update CAF closure with indirection
+  = UPD_CAF                            -- update CAF closure with indirection
   | UPD_BH_UPDATABLE                   -- eager backholing
   | UPD_BH_SINGLE_ENTRY                        -- more eager blackholing
   | PUSH_UPD_FRAME                     -- push update frame
-  | PUSH_SEQ_FRAME                     -- push seq frame
-  | UPDATE_SU_FROM_UPD_FRAME           -- pull Su out of the update frame
   | SET_TAG                            -- set TagReg if it exists
       -- dataToTag# primop -- *only* used in unregisterised builds.
       -- (see AbsCUtils.dsCOpStmt)
@@ -293,11 +270,10 @@ data CCheckMacro
   = HP_CHK_NP                          -- heap/stack checks when
   | STK_CHK_NP                         -- node points to the closure
   | HP_STK_CHK_NP
-  | HP_CHK_SEQ_NP                      -- for 'seq' style case alternatives
 
-  | HP_CHK                             -- heap/stack checks when
-  | STK_CHK                            -- node doesn't point
-  | HP_STK_CHK
+  | HP_CHK_FUN                         -- heap/stack checks when
+  | STK_CHK_FUN                                -- node doesn't point
+  | HP_STK_CHK_FUN
                                        -- case alternative heap checks:
 
   | HP_CHK_NOREGS                      --   no registers live
@@ -306,9 +282,8 @@ data CCheckMacro
   | HP_CHK_F1                          --   FloatReg1 (only) is live 
   | HP_CHK_D1                          --   DblReg1   (only) is live
   | HP_CHK_L1                          --   LngReg1   (only) is live
-  | HP_CHK_UT_ALT                      --   unboxed tuple return.
 
-  | HP_CHK_GEN                         -- generic heap check
+  | HP_CHK_UNBX_TUPLE                  -- unboxed tuple heap check
 \end{code}
 
 \item[@CCallProfCtrMacro@:]
@@ -376,10 +351,6 @@ data CAddrMode
        !PrimRep        -- the kind of the result
        CExprMacro      -- the macro to generate a value
        [CAddrMode]     -- and its arguments
-
-  | CBytesPerWord      -- Word size, in bytes, on this platform
-                       -- required for: half-word loads (used in fishing tags
-                       -- out of info tables), and sizeofByteArray#.
 \end{code}
 
 Various C macros for values which are dependent on the back-end layout.
@@ -390,9 +361,10 @@ data CExprMacro
   = ENTRY_CODE
   | ARG_TAG                            -- stack argument tagging
   | GET_TAG                            -- get current constructor tag
-  | UPD_FRAME_UPDATEE
   | CCS_HDR
-
+  | BYTE_ARR_CTS               -- used when passing a ByteArray# to a ccall
+  | PTRS_ARR_CTS               -- similarly for an Array#
+  | ForeignObj_CLOSURE_DATA    -- and again for a ForeignObj#
 \end{code}
 
 Convenience functions:
@@ -401,7 +373,10 @@ Convenience functions:
 mkIntCLit :: Int -> CAddrMode
 mkIntCLit i = CLit (mkMachInt (toInteger i))
 
-mkCString :: FAST_STRING -> CAddrMode
+mkWordCLit :: StgWord -> CAddrMode
+mkWordCLit wd = CLit (MachWord (fromIntegral wd))
+
+mkCString :: FastString -> CAddrMode
 mkCString s = CLit (MachStr s)
 
 mkCCostCentre :: CostCentre -> CAddrMode
@@ -458,16 +433,15 @@ vectors to indicate the state of the stack for the garbage collector.
 
 In the compiled program, liveness bitmaps that fit inside a single
 word (StgWord) are stored as a single word, while larger bitmaps are
-stored as a pointer to an array of words.  When we compile via C
-(especially when we bootstrap via HC files), we generate identical C
-code regardless of whether words are 32- or 64-bit on the target
-machine, by postponing the decision of how to store each liveness
-bitmap to C compilation time (or rather, C preprocessing time).
+stored as a pointer to an array of words. 
 
 \begin{code}
-type LivenessMask = [BitSet]
+data Liveness = Liveness CLabel !Int Bitmap
 
-data Liveness = Liveness CLabel LivenessMask
+maybeLargeBitmap :: Liveness -> AbstractC
+maybeLargeBitmap liveness@(Liveness _ size _)
+  | size <= mAX_SMALL_BITMAP_SIZE = AbsCNop
+  | otherwise                     = CBitmap liveness
 \end{code}
 
 %************************************************************************
@@ -485,9 +459,6 @@ type HeapOffset = Int                       -- ToDo: remove
 
 type VirtualHeapOffset = HeapOffset
 type VirtualSpOffset   = Int
-
-type HpRelOffset       = HeapOffset
-type SpRelOffset       = Int
 \end{code}
 
 %************************************************************************
@@ -513,7 +484,6 @@ data MagicId
 
   -- STG registers
   | Sp                 -- Stack ptr; points to last occupied stack location.
-  | Su                 -- Stack update frame pointer
   | SpLim              -- Stack limit
   | Hp                 -- Heap ptr; points to last occupied heap location.
   | HpLim              -- Heap limit register
@@ -543,7 +513,6 @@ instance Eq MagicId where
      where
        tag BaseReg          = (_ILIT(0) :: FastInt)
        tag Sp               = _ILIT(1)
-       tag Su               = _ILIT(2)
        tag SpLim            = _ILIT(3)
        tag Hp               = _ILIT(4)
        tag HpLim            = _ILIT(5)