[project @ 2001-03-13 14:18:47 by simonmar]
[ghc-hetmet.git] / ghc / compiler / codeGen / SMRep.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
3 %
4 \section[SMRep]{Storage manager representations of closure}
5
6 This is here, rather than in ClosureInfo, just to keep nhc happy.
7 Other modules should access this info through ClosureInfo.
8
9 \begin{code}
10 module SMRep (
11         SMRep(..), ClosureType(..),
12         isStaticRep,
13         fixedHdrSize, arrWordsHdrSize, arrPtrsHdrSize,
14         fixedItblSize, pprSMRep
15
16 #ifndef OMIT_NATIVE_CODEGEN
17         , getSMRepClosureTypeInt
18         , cONSTR
19         , cONSTR_1_0
20         , cONSTR_0_1
21         , cONSTR_2_0
22         , cONSTR_1_1
23         , cONSTR_0_2
24         , cONSTR_STATIC
25         , cONSTR_NOCAF_STATIC
26         , fUN
27         , fUN_1_0
28         , fUN_0_1
29         , fUN_2_0
30         , fUN_1_1
31         , fUN_0_2
32         , fUN_STATIC
33         , tHUNK
34         , tHUNK_1_0
35         , tHUNK_0_1
36         , tHUNK_2_0
37         , tHUNK_1_1
38         , tHUNK_0_2
39         , tHUNK_STATIC
40         , tHUNK_SELECTOR
41         , rET_SMALL
42         , rET_VEC_SMALL
43         , rET_BIG
44         , rET_VEC_BIG
45         , bLACKHOLE
46 #endif
47     ) where
48
49 #include "HsVersions.h"
50
51 import CmdLineOpts
52 import AbsCSyn          ( Liveness(..) )
53 import Constants        ( sTD_HDR_SIZE, pROF_HDR_SIZE,
54                           gRAN_HDR_SIZE, tICKY_HDR_SIZE, 
55                           aRR_WORDS_HDR_SIZE, aRR_PTRS_HDR_SIZE,
56                           sTD_ITBL_SIZE, pROF_ITBL_SIZE,
57                           gRAN_ITBL_SIZE, tICKY_ITBL_SIZE )
58 import Outputable
59 \end{code}
60
61 %************************************************************************
62 %*                                                                      *
63 \subsubsection[SMRep-datatype]{@SMRep@---storage manager representation}
64 %*                                                                      *
65 %************************************************************************
66
67 \begin{code}
68 data SMRep
69      -- static closure have an extra static link field at the end.
70   = GenericRep          -- GC routines consult sizes in info tbl
71         Bool            -- True <=> This is a static closure.  Affects how 
72                         --          we garbage-collect it
73         Int             -- # ptr words
74         Int             -- # non-ptr words
75         ClosureType     -- closure type
76
77   | BlackHoleRep
78
79 data ClosureType        -- Corresponds 1-1 with the varieties of closures
80                         -- implemented by the RTS.  Compare with ghc/includes/ClosureTypes.h
81     = CONSTR
82     | CONSTR_p_n        -- The p_n variants have more efficient GC, but we
83                         -- only provide them for dynamically-allocated closures
84                         -- (We could do them for static ones, but we don't)
85     | CONSTR_NOCAF
86     | FUN
87     | FUN_p_n
88     | THUNK
89     | THUNK_p_n
90     | THUNK_SELECTOR
91   deriving (Eq,Ord)
92 \end{code}
93
94 Size of a closure header.
95
96 \begin{code}
97 fixedHdrSize :: Int{-words-}
98 fixedHdrSize = sTD_HDR_SIZE + profHdrSize + granHdrSize + tickyHdrSize
99
100 profHdrSize  :: Int{-words-}
101 profHdrSize  | opt_SccProfilingOn   = pROF_HDR_SIZE
102              | otherwise            = 0
103
104 granHdrSize  :: Int{-words-}
105 granHdrSize  | opt_GranMacros       = gRAN_HDR_SIZE
106              | otherwise            = 0
107
108 tickyHdrSize :: Int{-words-}
109 tickyHdrSize | opt_DoTickyProfiling = tICKY_HDR_SIZE
110              | otherwise            = 0
111
112 arrWordsHdrSize   :: Int{-words-}
113 arrWordsHdrSize   = fixedHdrSize + aRR_WORDS_HDR_SIZE
114
115 arrPtrsHdrSize   :: Int{-words-}
116 arrPtrsHdrSize   = fixedHdrSize + aRR_PTRS_HDR_SIZE
117 \end{code}
118
119 Size of an info table.
120
121 \begin{code}
122 fixedItblSize :: Int{-words-}
123 fixedItblSize = sTD_ITBL_SIZE + profItblSize + granItblSize + tickyItblSize
124
125 profItblSize  :: Int{-words-}
126 profItblSize  | opt_SccProfilingOn   = pROF_ITBL_SIZE
127               | otherwise           = 0
128
129 granItblSize  :: Int{-words-}
130 granItblSize  | opt_GranMacros      = gRAN_ITBL_SIZE
131               | otherwise           = 0
132
133 tickyItblSize :: Int{-words-}
134 tickyItblSize | opt_DoTickyProfiling = tICKY_ITBL_SIZE
135               | otherwise           = 0
136 \end{code}
137
138 \begin{code}
139 isStaticRep :: SMRep -> Bool
140 isStaticRep (GenericRep is_static _ _ _) = is_static
141 isStaticRep BlackHoleRep                 = False
142 \end{code}
143
144 \begin{code}
145 instance Outputable SMRep where
146     ppr rep = pprSMRep rep
147
148 pprSMRep :: SMRep -> SDoc
149 pprSMRep (GenericRep True  ptrs nptrs clo_ty) = pprClosureType clo_ty ptrs nptrs <> ptext SLIT("_STATIC")
150 pprSMRep (GenericRep False ptrs nptrs clo_ty) = pprClosureType clo_ty ptrs nptrs
151
152 pprClosureType CONSTR         p n = ptext SLIT("CONSTR")
153 pprClosureType CONSTR_p_n     p n = ptext SLIT("CONSTR_") <> int p <> char '_' <> int n
154 pprClosureType CONSTR_NOCAF   p n = ptext SLIT("CONSTR_NOCAF")
155 pprClosureType FUN            p n = ptext SLIT("FUN")
156 pprClosureType FUN_p_n        p n = ptext SLIT("FUN_") <> int p <> char '_' <> int n
157 pprClosureType THUNK          p n = ptext SLIT("THUNK")
158 pprClosureType THUNK_p_n      p n = ptext SLIT("THUNK_") <> int p <> char '_' <> int n
159 pprClosureType THUNK_SELECTOR p n = ptext SLIT("THUNK_SELECTOR")
160
161 #ifndef OMIT_NATIVE_CODEGEN
162 getSMRepClosureTypeInt :: SMRep -> Int
163 getSMRepClosureTypeInt (GenericRep False _ _ CONSTR)     = cONSTR
164 getSMRepClosureTypeInt (GenericRep False 1 0 CONSTR_p_n) = cONSTR_1_0
165 getSMRepClosureTypeInt (GenericRep False 0 1 CONSTR_p_n) = cONSTR_0_1
166 getSMRepClosureTypeInt (GenericRep False 2 0 CONSTR_p_n) = cONSTR_2_0
167 getSMRepClosureTypeInt (GenericRep False 1 1 CONSTR_p_n) = cONSTR_1_1
168 getSMRepClosureTypeInt (GenericRep False 0 2 CONSTR_p_n) = cONSTR_0_2
169
170 getSMRepClosureTypeInt (GenericRep False _ _ FUN)     = fUN
171 getSMRepClosureTypeInt (GenericRep False 1 0 FUN_p_n) = fUN_1_0
172 getSMRepClosureTypeInt (GenericRep False 0 1 FUN_p_n) = fUN_0_1
173 getSMRepClosureTypeInt (GenericRep False 2 0 FUN_p_n) = fUN_2_0
174 getSMRepClosureTypeInt (GenericRep False 1 1 FUN_p_n) = fUN_1_1
175 getSMRepClosureTypeInt (GenericRep False 0 2 FUN_p_n) = fUN_0_2
176
177 getSMRepClosureTypeInt (GenericRep False _ _ THUNK)     = tHUNK
178 getSMRepClosureTypeInt (GenericRep False 1 0 THUNK_p_n) = tHUNK_1_0
179 getSMRepClosureTypeInt (GenericRep False 0 1 THUNK_p_n) = tHUNK_0_1
180 getSMRepClosureTypeInt (GenericRep False 2 0 THUNK_p_n) = tHUNK_2_0
181 getSMRepClosureTypeInt (GenericRep False 1 1 THUNK_p_n) = tHUNK_1_1
182 getSMRepClosureTypeInt (GenericRep False 0 2 THUNK_p_n) = tHUNK_0_2
183
184 getSMRepClosureTypeInt (GenericRep False _ _ THUNK_SELECTOR) =  tHUNK_SELECTOR
185
186 getSMRepClosureTypeInt (GenericRep True _ _ CONSTR)       = cONSTR_STATIC
187 getSMRepClosureTypeInt (GenericRep True _ _ CONSTR_NOCAF) = cONSTR_NOCAF_STATIC
188 getSMRepClosureTypeInt (GenericRep True _ _ FUN)          = fUN_STATIC
189 getSMRepClosureTypeInt (GenericRep True _ _ THUNK)        = tHUNK_STATIC
190
191 getSMRepClosureTypeInt BlackHoleRep = bLACKHOLE
192
193 getSMRepClosureTypeInt rep = pprPanic "getSMRepClosureTypeInt:" (pprSMRep rep)
194
195
196 -- Just the ones we need:
197
198 #include "../includes/ClosureTypes.h"
199
200 cONSTR                  = (CONSTR               :: Int)
201 cONSTR_1_0              = (CONSTR_1_0           :: Int)
202 cONSTR_0_1              = (CONSTR_0_1           :: Int)
203 cONSTR_2_0              = (CONSTR_2_0           :: Int)
204 cONSTR_1_1              = (CONSTR_1_1           :: Int)
205 cONSTR_0_2              = (CONSTR_0_2           :: Int)
206 cONSTR_STATIC           = (CONSTR_STATIC        :: Int)
207 cONSTR_NOCAF_STATIC     = (CONSTR_NOCAF_STATIC  :: Int)
208 fUN                     = (FUN                  :: Int)
209 fUN_1_0                 = (FUN_1_0              :: Int)
210 fUN_0_1                 = (FUN_0_1              :: Int)
211 fUN_2_0                 = (FUN_2_0              :: Int)
212 fUN_1_1                 = (FUN_1_1              :: Int)
213 fUN_0_2                 = (FUN_0_2              :: Int)
214 fUN_STATIC              = (FUN_STATIC           :: Int)
215 tHUNK                   = (THUNK                :: Int)
216 tHUNK_1_0               = (THUNK_1_0            :: Int)
217 tHUNK_0_1               = (THUNK_0_1            :: Int)
218 tHUNK_2_0               = (THUNK_2_0            :: Int)
219 tHUNK_1_1               = (THUNK_1_1            :: Int)
220 tHUNK_0_2               = (THUNK_0_2            :: Int)
221 tHUNK_STATIC            = (THUNK_STATIC         :: Int)
222 tHUNK_SELECTOR          = (THUNK_SELECTOR       :: Int)
223 rET_SMALL               = (RET_SMALL            :: Int)
224 rET_VEC_SMALL           = (RET_VEC_SMALL        :: Int)
225 rET_BIG                 = (RET_BIG              :: Int)
226 rET_VEC_BIG             = (RET_VEC_BIG          :: Int)
227 bLACKHOLE               = (BLACKHOLE            :: Int)
228
229 #endif OMIT_NATIVE_CODEGEN
230 \end{code}