X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2FcodeGen%2FSMRep.lhs;h=4f53f4bfee641910ad0a8062effb45fc635c4fe6;hb=425008f93f115f9d5c92543e32838a47a7a7790f;hp=8270d3eea4fa9da31d94be4b186aa4f85cd03ab1;hpb=438596897ebbe25a07e1c82085cfbc5bdb00f09e;p=ghc-hetmet.git diff --git a/ghc/compiler/codeGen/SMRep.lhs b/ghc/compiler/codeGen/SMRep.lhs index 8270d3e..4f53f4b 100644 --- a/ghc/compiler/codeGen/SMRep.lhs +++ b/ghc/compiler/codeGen/SMRep.lhs @@ -9,38 +9,24 @@ Other modules should access this info through ClosureInfo. \begin{code} module SMRep ( SMRep(..), ClosureType(..), - isConstantRep, isStaticRep, - fixedHdrSize, arrHdrSize, fixedItblSize, getSMRepStr, getClosureTypeStr - -#ifndef OMIT_NATIVE_CODEGEN - , getSMRepClosureTypeInt - , cONSTR - , cONSTR_STATIC - , cONSTR_NOCAF_STATIC - , fUN - , fUN_STATIC - , tHUNK - , tHUNK_STATIC - , tHUNK_SELECTOR - , rET_SMALL - , rET_VEC_SMALL - , rET_BIG - , rET_VEC_BIG - , bLACKHOLE -#endif + isStaticRep, + fixedHdrSize, arrWordsHdrSize, arrPtrsHdrSize, + stdItblSize, retItblSize, + getSMRepClosureTypeInt, + + rET_SMALL, rET_VEC_SMALL, rET_BIG, rET_VEC_BIG, + + StgWord, StgHalfWord, hALF_WORD, ) where #include "HsVersions.h" +#include "../includes/MachDeps.h" import CmdLineOpts -import AbsCSyn ( Liveness(..) ) -import Constants ( sTD_HDR_SIZE, pROF_HDR_SIZE, - gRAN_HDR_SIZE, tICKY_HDR_SIZE, aRR_HDR_SIZE, - sTD_ITBL_SIZE, pROF_ITBL_SIZE, - gRAN_ITBL_SIZE, tICKY_ITBL_SIZE ) +import Constants import Outputable -import Util ( panic ) -import GlaExts ( Int(..), Int#, (<#), (==#), (<#), (>#) ) + +import DATA_WORD \end{code} %************************************************************************ @@ -52,35 +38,29 @@ import GlaExts ( Int(..), Int#, (<#), (==#), (<#), (>#) ) \begin{code} data SMRep -- static closure have an extra static link field at the end. - = StaticRep - Int -- # ptr words (useful for interpreter, debugger, etc) - Int -- # non-ptr words - ClosureType -- closure type - - | GenericRep -- GC routines consult sizes in info tbl - Int -- # ptr words - Int -- # non-ptr words + = GenericRep -- GC routines consult sizes in info tbl + Bool -- True <=> This is a static closure. Affects how + -- we garbage-collect it + !Int -- # ptr words + !Int -- # non-ptr words ClosureType -- closure type - | ConstantRep -- CONSTR with zero-arity - | BlackHoleRep -data ClosureType - = CONSTR - | CONSTR_NOCAF - | FUN - | THUNK - | THUNK_SELECTOR - deriving (Eq,Ord) - +data ClosureType -- Corresponds 1-1 with the varieties of closures + -- implemented by the RTS. Compare with ghc/includes/ClosureTypes.h + = Constr + | ConstrNoCaf + | Fun + | Thunk + | ThunkSelector \end{code} Size of a closure header. \begin{code} fixedHdrSize :: Int{-words-} -fixedHdrSize = sTD_HDR_SIZE + profHdrSize + granHdrSize + tickyHdrSize +fixedHdrSize = sTD_HDR_SIZE + profHdrSize + granHdrSize profHdrSize :: Int{-words-} profHdrSize | opt_SccProfilingOn = pROF_HDR_SIZE @@ -90,22 +70,24 @@ granHdrSize :: Int{-words-} granHdrSize | opt_GranMacros = gRAN_HDR_SIZE | otherwise = 0 -tickyHdrSize :: Int{-words-} -tickyHdrSize | opt_DoTickyProfiling = tICKY_HDR_SIZE - | otherwise = 0 +arrWordsHdrSize :: Int{-words-} +arrWordsHdrSize = fixedHdrSize + aRR_WORDS_HDR_SIZE -arrHdrSize :: Int{-words-} -arrHdrSize = fixedHdrSize + aRR_HDR_SIZE +arrPtrsHdrSize :: Int{-words-} +arrPtrsHdrSize = fixedHdrSize + aRR_PTRS_HDR_SIZE \end{code} Size of an info table. \begin{code} -fixedItblSize :: Int{-words-} -fixedItblSize = sTD_ITBL_SIZE + profItblSize + granItblSize + tickyItblSize +stdItblSize :: Int{-words-} +stdItblSize = sTD_ITBL_SIZE + profItblSize + granItblSize + tickyItblSize + +retItblSize :: Int{-words-} +retItblSize = stdItblSize + rET_ITBL_SIZE profItblSize :: Int{-words-} -profItblSize | opt_SccProfilingOn = pROF_ITBL_SIZE +profItblSize | opt_SccProfilingOn = pROF_ITBL_SIZE | otherwise = 0 granItblSize :: Int{-words-} @@ -114,79 +96,72 @@ granItblSize | opt_GranMacros = gRAN_ITBL_SIZE tickyItblSize :: Int{-words-} tickyItblSize | opt_DoTickyProfiling = tICKY_ITBL_SIZE - | otherwise = 0 + | otherwise = 0 \end{code} \begin{code} -isConstantRep, isStaticRep :: SMRep -> Bool -isConstantRep ConstantRep = True -isConstantRep other = False - -isStaticRep (StaticRep _ _ _) = True -isStaticRep _ = False +isStaticRep :: SMRep -> Bool +isStaticRep (GenericRep is_static _ _ _) = is_static +isStaticRep BlackHoleRep = False \end{code} \begin{code} -{- ToDo: needed? -} -instance Text SMRep where - showsPrec d rep - = showString (case rep of - StaticRep _ _ _ -> "STATIC" - GenericRep _ _ _ -> "" - ConstantRep -> "") - -instance Outputable SMRep where - ppr rep = text (show rep) - -getSMRepStr (GenericRep _ _ t) = getClosureTypeStr t -getSMRepStr (StaticRep _ _ t) = getClosureTypeStr t ++ "_STATIC" -getSMRepStr ConstantRep = "CONSTR_NOCAF_STATIC" -getSMRepStr BlackHoleRep = "BLACKHOLE" - -getClosureTypeStr CONSTR = "CONSTR" -getClosureTypeStr CONSTR_NOCAF = "CONSTR_NOCAF" -getClosureTypeStr FUN = "FUN" -getClosureTypeStr THUNK = "THUNK" -getClosureTypeStr THUNK_SELECTOR = "THUNK_SELECTOR" - -#ifndef OMIT_NATIVE_CODEGEN +#include "../includes/ClosureTypes.h" +-- Defines CONSTR, CONSTR_1_0 etc + getSMRepClosureTypeInt :: SMRep -> Int -getSMRepClosureTypeInt (GenericRep _ _ t) = - case t of - CONSTR -> cONSTR - CONSTR_NOCAF -> panic "getClosureTypeInt: CONSTR_NOCAF" - FUN -> fUN - THUNK -> tHUNK - THUNK_SELECTOR -> tHUNK_SELECTOR -getSMRepClosureTypeInt (StaticRep _ _ t) = - case t of - CONSTR -> cONSTR_STATIC - CONSTR_NOCAF -> cONSTR_NOCAF_STATIC - FUN -> fUN_STATIC - THUNK -> tHUNK_STATIC - THUNK_SELECTOR -> panic "getClosureTypeInt: THUNK_SELECTOR_STATIC" - -getSMRepClosureTypeInt ConstantRep = cONSTR_NOCAF_STATIC - -getSMRepClosureTypeInt BlackHoleRep = bLACKHOLE - --- Just the ones we need: +getSMRepClosureTypeInt (GenericRep False 1 0 Constr) = CONSTR_1_0 +getSMRepClosureTypeInt (GenericRep False 0 1 Constr) = CONSTR_0_1 +getSMRepClosureTypeInt (GenericRep False 2 0 Constr) = CONSTR_2_0 +getSMRepClosureTypeInt (GenericRep False 1 1 Constr) = CONSTR_1_1 +getSMRepClosureTypeInt (GenericRep False 0 2 Constr) = CONSTR_0_2 +getSMRepClosureTypeInt (GenericRep False _ _ Constr) = CONSTR + +getSMRepClosureTypeInt (GenericRep False 1 0 Fun) = FUN_1_0 +getSMRepClosureTypeInt (GenericRep False 0 1 Fun) = FUN_0_1 +getSMRepClosureTypeInt (GenericRep False 2 0 Fun) = FUN_2_0 +getSMRepClosureTypeInt (GenericRep False 1 1 Fun) = FUN_1_1 +getSMRepClosureTypeInt (GenericRep False 0 2 Fun) = FUN_0_2 +getSMRepClosureTypeInt (GenericRep False _ _ Fun) = FUN + +getSMRepClosureTypeInt (GenericRep False 1 0 Thunk) = THUNK_1_0 +getSMRepClosureTypeInt (GenericRep False 0 1 Thunk) = THUNK_0_1 +getSMRepClosureTypeInt (GenericRep False 2 0 Thunk) = THUNK_2_0 +getSMRepClosureTypeInt (GenericRep False 1 1 Thunk) = THUNK_1_1 +getSMRepClosureTypeInt (GenericRep False 0 2 Thunk) = THUNK_0_2 +getSMRepClosureTypeInt (GenericRep False _ _ Thunk) = THUNK + +getSMRepClosureTypeInt (GenericRep False _ _ ThunkSelector) = THUNK_SELECTOR + +getSMRepClosureTypeInt (GenericRep True _ _ Constr) = CONSTR_STATIC +getSMRepClosureTypeInt (GenericRep True _ _ ConstrNoCaf) = CONSTR_NOCAF_STATIC +getSMRepClosureTypeInt (GenericRep True _ _ Fun) = FUN_STATIC +getSMRepClosureTypeInt (GenericRep True _ _ Thunk) = THUNK_STATIC + +getSMRepClosureTypeInt BlackHoleRep = BLACKHOLE + +getSMRepClosureTypeInt rep = panic "getSMRepClosureTypeInt" + + +-- We export these ones +rET_SMALL = (RET_SMALL :: Int) +rET_VEC_SMALL = (RET_VEC_SMALL :: Int) +rET_BIG = (RET_BIG :: Int) +rET_VEC_BIG = (RET_VEC_BIG :: Int) +\end{code} -#include "../includes/ClosureTypes.h" +A type representing an StgWord on the target platform. -cONSTR = (CONSTR :: Int) -cONSTR_STATIC = (CONSTR_STATIC :: Int) -cONSTR_NOCAF_STATIC = (CONSTR_NOCAF_STATIC :: Int) -fUN = (FUN :: Int) -fUN_STATIC = (FUN_STATIC :: Int) -tHUNK = (THUNK :: Int) -tHUNK_STATIC = (THUNK_STATIC :: Int) -tHUNK_SELECTOR = (THUNK_SELECTOR :: Int) -rET_SMALL = (RET_SMALL :: Int) -rET_VEC_SMALL = (RET_VEC_SMALL :: Int) -rET_BIG = (RET_BIG :: Int) -rET_VEC_BIG = (RET_VEC_BIG :: Int) -bLACKHOLE = (BLACKHOLE :: Int) - -#endif OMIT_NATIVE_CODEGEN +\begin{code} +#if SIZEOF_HSWORD == 4 +type StgWord = Word32 +type StgHalfWord = Word16 +hALF_WORD = 16 :: Int +#elif SIZEOF_HSWORD == 8 +type StgWord = Word64 +type StgHalfWord = Word32 +hALF_WORD = 32 :: Int +#else +#error unknown SIZEOF_HSWORD +#endif \end{code}