X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2FnativeGen%2FStixInfo.lhs;h=fa1c07dd2464aa682e700e942066c9e58ad0e3c2;hb=f62fd70df7695286af55854911dad8a28eecb5e1;hp=b72675f185302d053338d31f4b8a2608698d8b72;hpb=74b1006ed8565ff3c39edcdaf859d606dd652641;p=ghc-hetmet.git diff --git a/ghc/compiler/nativeGen/StixInfo.lhs b/ghc/compiler/nativeGen/StixInfo.lhs index b72675f..fa1c07d 100644 --- a/ghc/compiler/nativeGen/StixInfo.lhs +++ b/ghc/compiler/nativeGen/StixInfo.lhs @@ -3,10 +3,17 @@ % \begin{code} -module StixInfo ( genCodeInfoTable, genBitmapInfoTable ) where +module StixInfo ( + + genCodeInfoTable, genBitmapInfoTable, + + bitmapToIntegers, bitmapIsSmall, livenessIsSmall + + ) where #include "HsVersions.h" #include "../includes/config.h" +#include "NCG.h" import AbsCSyn ( AbstractC(..), Liveness(..) ) import CLabel ( CLabel ) @@ -14,17 +21,21 @@ import StgSyn ( SRT(..) ) import ClosureInfo ( closurePtrsSize, closureNonHdrSize, closureSMRep, infoTableLabelFromCI, - infoTblNeedsSRT, getSRTInfo + infoTblNeedsSRT, getSRTInfo, closureSemiTag ) import PrimRep ( PrimRep(..) ) -import SMRep ( SMRep(..), getSMRepClosureTypeInt ) +import SMRep ( getSMRepClosureTypeInt ) import Stix -- all of it import UniqSupply ( returnUs, UniqSM ) -import Outputable ( int ) -import BitSet ( intBS ) +import BitSet ( BitSet, intBS ) +import Maybes ( maybeToBool ) import Bits import Word + +#if __GLASGOW_HASKELL__ >= 404 +import GlaExts ( fromInt ) +#endif \end{code} Generating code for info tables (arrays of data). @@ -38,10 +49,11 @@ genCodeInfoTable (CClosureInfoAndCode cl_info _ _ cl_descr) = returnUs (\xs -> StData PtrRep table : StLabel info_lbl : xs) where - info_lbl = infoTableLabelFromCI cl_info + info_lbl = infoTableLabelFromCI cl_info + needs_srt = infoTblNeedsSRT cl_info - table | infoTblNeedsSRT cl_info = srt_label : rest_of_table - | otherwise = rest_of_table + table | needs_srt = srt_label : rest_of_table + | otherwise = rest_of_table rest_of_table = [ @@ -54,22 +66,28 @@ genCodeInfoTable (CClosureInfoAndCode cl_info _ _ cl_descr) -- ToDo: do this using .byte and .word directives. type_info :: Word32 #ifdef WORDS_BIGENDIAN - type_info = (fromInt flags `shiftL` 24) .|. - (fromInt closure_type `shiftL` 16) .|. + type_info = (fromInt closure_type `shiftL` 16) .|. (fromInt srt_len) #else - type_info = (fromInt flags) .|. - (fromInt closure_type `shiftL` 8) .|. + type_info = (fromInt closure_type) .|. (fromInt srt_len `shiftL` 16) #endif srt = getSRTInfo cl_info - (srt_label,srt_len) = - case srt of - (lbl, NoSRT) -> (StInt 0, 0) + (srt_label,srt_len) + | is_constr + = (StInt 0, tag) + | needs_srt + = case srt of (lbl, SRT off len) -> (StIndex DataPtrRep (StCLbl lbl) (StInt (toInteger off)), len) + | otherwise + = (StInt 0, 0) + + maybe_tag = closureSemiTag cl_info + is_constr = maybeToBool maybe_tag + (Just tag) = maybe_tag layout_info :: Word32 #ifdef WORDS_BIGENDIAN @@ -85,7 +103,6 @@ genCodeInfoTable (CClosureInfoAndCode cl_info _ _ cl_descr) closure_type = getSMRepClosureTypeInt (closureSMRep cl_info) - flags = 0 -- for now genBitmapInfoTable @@ -112,17 +129,18 @@ genBitmapInfoTable liveness srt closure_type include_srt ] layout_info = case liveness of - LvSmall mask -> StInt (toInteger (intBS mask)) - LvLarge lbl -> StCLbl lbl + Liveness lbl mask -> + case bitmapToIntegers mask of + [ ] -> StInt 0 + [i] -> StInt i + _ -> StCLbl lbl type_info :: Word32 #ifdef WORDS_BIGENDIAN - type_info = (fromInt flags `shiftL` 24) .|. - (fromInt closure_type `shiftL` 16) .|. + type_info = (fromInt closure_type `shiftL` 16) .|. (fromInt srt_len) #else - type_info = (fromInt flags) .|. - (fromInt closure_type `shiftL` 8) .|. + type_info = (fromInt closure_type) .|. (fromInt srt_len `shiftL` 16) #endif @@ -133,5 +151,27 @@ genBitmapInfoTable liveness srt closure_type include_srt (StIndex DataPtrRep (StCLbl lbl) (StInt (toInteger off)), len) - flags = 0 -- for now +bitmapToIntegers :: [BitSet] -> [Integer] +bitmapToIntegers = bundle . map (toInteger . intBS) + where +#if BYTES_PER_WORD == 4 + bundle = id +#else + bundle [] = [] + bundle is = case splitAt (BYTES_PER_WORD/4) is of + (these, those) -> + ( foldr1 (\x y -> x + 4294967296 * y) + [x `mod` 4294967296 | x <- these] + : bundle those + ) +#endif + +bitmapIsSmall :: [BitSet] -> Bool +bitmapIsSmall bitmap + = case bitmapToIntegers bitmap of + _:_:_ -> False + _ -> True + +livenessIsSmall :: Liveness -> Bool +livenessIsSmall (Liveness _ mask) = bitmapIsSmall mask \end{code}