[project @ 1996-06-05 06:44:31 by partain]
[ghc-hetmet.git] / ghc / compiler / codeGen / SMRep.lhs
index fb5b113..7c46adf 100644 (file)
@@ -1,5 +1,5 @@
 %
-% (c) The GRASP/AQUA Project, Glasgow University, 1992-1995
+% (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
 %
 \section[SMRep]{Storage manager representations of closure}
 
@@ -12,12 +12,15 @@ Other modules should access this info through ClosureInfo.
 module SMRep (
        SMRep(..), SMSpecRepKind(..), SMUpdateKind(..),
        getSMInfoStr, getSMInitHdrStr, getSMUpdInplaceHdrStr,
-       ltSMRepHdr -- UNUSED, equivSMRepHdr
+       ltSMRepHdr,
+       isConstantRep, isSpecRep, isStaticRep, isPhantomRep,
+       isIntLikeRep
     ) where
 
-import Outputable
-import Pretty
-import Util
+IMP_Ubiq(){-uitous-}
+
+import Pretty          ( ppStr )
+import Util            ( panic )
 \end{code}
 
 %************************************************************************
@@ -57,12 +60,12 @@ data SMRep
        SMSpecRepKind   -- Which kind of specialised representation
        Int             -- # ptr words
        Int             -- # non-ptr words
-        SMUpdateKind           -- Updatable?
+       SMUpdateKind    -- Updatable?
 
   | GenericRep         -- GC routines consult sizes in info tbl
        Int             -- # ptr words
        Int             -- # non-ptr words
-        SMUpdateKind   -- Updatable?
+       SMUpdateKind    -- Updatable?
 
   | BigTupleRep                -- All ptrs, size in var-hdr field
                        -- Used for big tuples
@@ -83,6 +86,72 @@ data SMRep
                        -- Used for mutable tuples
        Int             -- # ptr words
 
+{- Mattson review:
+
+To: simonpj@dcs.gla.ac.uk, partain@dcs.gla.ac.uk
+Cc: kh@dcs.gla.ac.uk, trinder@dcs.gla.ac.uk, areid@dcs.gla.ac.uk
+Subject: Correct me if I'm wrong...
+Date: Fri, 17 Feb 1995 18:09:00 +0000
+From: Jim Mattson <mattson@dcs.gla.ac.uk>
+
+BigTupleRep == TUPLE
+
+    Never generated by the compiler, and only used in the RTS when
+    mutuples don't require special attention at GC time (e.g. 2s)
+    When it is used, it is a primitive object (never entered).
+    May be mutable...probably should never be used in the parallel
+    system, since we need to distinguish mutables from immutables when
+    deciding whether to copy or move closures across processors.
+
+DataRep == DATA (aka MutableByteArray & ByteArray)
+    Never generated by the compiler, and only used in the RTS for
+    ArrayOfData.  Always a primitive object (never entered).  May
+    be mutable...though we don't distinguish between mutable and
+    immutable data arrays in the sequential world, it would probably
+    be useful in the parallel world to know when it is safe to just
+    copy one of these.  I believe the hooks are in place for changing
+    the InfoPtr on a MutableByteArray when it's frozen to a ByteArray
+    if we want to do so.
+
+DynamicRep == DYN
+    Never generated by the compiler, and only used in the RTS for
+    PAPs and the Stable Pointer table.  PAPs are non-primitive,
+    non-updatable, normal-form objects, but the SPT is a primitive,
+    mutable object.  At the moment, there is no SPT in the parallel
+    world.  Presumably, it would be possible to have an SPT on each
+    processor, and we could identify a stable pointer as a (processor,
+    SPT-entry) pair, but would it be worth it?
+
+MuTupleRep == MUTUPLE
+    Never generated by the compiler, and only used in the RTS when
+    mutuples *do* require special attention at GC time.
+    When it is used, it is a primitive object (never entered).
+    Always mutable...there is an IMMUTUPLE in the RTS, but no
+    corresponding type in the compiler.
+
+--jim
+-}
+\end{code}
+
+\begin{code}
+isConstantRep, isSpecRep, isStaticRep, isPhantomRep, isIntLikeRep :: SMRep -> Bool
+isConstantRep (SpecialisedRep ConstantRep _ _ _)   = True
+isConstantRep other                               = False
+
+isSpecRep (SpecialisedRep kind _ _ _)  = True    -- All the kinds of Spec closures
+isSpecRep other                                = False   -- True indicates that the _VHS is 0 !
+
+isStaticRep (StaticRep _ _) = True
+isStaticRep _              = False
+
+isPhantomRep PhantomRep        = True
+isPhantomRep _         = False
+
+isIntLikeRep (SpecialisedRep IntLikeRep _ _ _)   = True
+isIntLikeRep other                              = False
+\end{code}
+
+\begin{code}
 instance Eq SMRep where
     (SpecialisedRep k1 a1 b1 _) == (SpecialisedRep k2 a2 b2 _) = (tagOf_SMSpecRepKind k1) _EQ_ (tagOf_SMSpecRepKind k2)
                                                               && a1 == a2 && b1 == b2
@@ -92,11 +161,6 @@ instance Eq SMRep where
     (DataRep a1)             == (DataRep a2)              = a1 == a2
     a                        == b                         = (tagOf_SMRep a) _EQ_ (tagOf_SMRep b)
 
-{- UNUSED:
-equivSMRepHdr :: SMRep -> SMRep -> Bool
-a `equivSMRepHdr` b = (tagOf_SMRep a) _EQ_ (tagOf_SMRep b)
--}
-
 ltSMRepHdr :: SMRep -> SMRep -> Bool
 a `ltSMRepHdr` b = (tagOf_SMRep a) _LT_ (tagOf_SMRep b)
 
@@ -137,8 +201,8 @@ tagOf_SMRep PhantomRep                   = ILIT(8)
 tagOf_SMRep (MuTupleRep _)          = ILIT(9)
 
 instance Text SMRep where
-    showsPrec d rep rest
-      = (case rep of
+    showsPrec d rep
+      = showString (case rep of
           StaticRep _ _                         -> "STATIC"
           SpecialisedRep kind _ _ SMNormalForm  -> "SPEC_N"
           SpecialisedRep kind _ _ SMSingleEntry -> "SPEC_S"
@@ -146,12 +210,12 @@ instance Text SMRep where
           GenericRep _ _ SMNormalForm           -> "GEN_N"
           GenericRep _ _ SMSingleEntry          -> "GEN_S"
           GenericRep _ _ SMUpdatable            -> "GEN_U"
-          BigTupleRep _                 -> "TUPLE"
-          DataRep       _               -> "DATA"
-          DynamicRep                    -> "DYN"
-          BlackHoleRep                  -> "BH"
-          PhantomRep                    -> "INREGS"
-          MuTupleRep _                  -> "MUTUPLE") ++ rest
+          BigTupleRep _                         -> "TUPLE"
+          DataRep       _                       -> "DATA"
+          DynamicRep                            -> "DYN"
+          BlackHoleRep                          -> "BH"
+          PhantomRep                            -> "INREGS"
+          MuTupleRep _                          -> "MUTUPLE")
 
 instance Outputable SMRep where
     ppr sty rep = ppStr (show rep)