[project @ 2003-03-25 16:19:55 by sof]
[ghc-hetmet.git] / ghc / includes / InfoTables.h
1 /* ----------------------------------------------------------------------------
2  * $Id: InfoTables.h,v 1.28 2002/12/11 15:36:37 simonmar Exp $
3  * 
4  * (c) The GHC Team, 1998-2002
5  *
6  * Info Tables
7  *
8  * -------------------------------------------------------------------------- */
9
10 #ifndef INFOTABLES_H
11 #define INFOTABLES_H
12
13 /* -----------------------------------------------------------------------------
14    Profiling info
15    -------------------------------------------------------------------------- */
16
17 typedef struct {
18     char *closure_type;
19     char *closure_desc;
20 } StgProfInfo;
21
22 /* -----------------------------------------------------------------------------
23    Parallelism info
24    -------------------------------------------------------------------------- */
25
26 #if 0 && (defined(PAR) || defined(GRAN))
27
28 // CURRENTLY UNUSED
29 // ToDo: use this in StgInfoTable (mutually recursive) -- HWL
30
31 typedef struct {
32   StgInfoTable *rbh_infoptr;     /* infoptr to the RBH  */
33 } StgParInfo;
34
35 #endif /* 0 */
36
37 /*
38    Copied from ghc-0.29; ToDo: check this code -- HWL
39
40    In the parallel system, all updatable closures have corresponding
41    revertible black holes.  When we are assembly-mangling, we guarantee
42    that the revertible black hole code precedes the normal entry code, so
43    that the RBH info table resides at a fixed offset from the normal info
44    table.  Otherwise, we add the RBH info table pointer to the end of the
45    normal info table and vice versa.
46
47    Currently has to use a !RBH_MAGIC_OFFSET setting.
48    Still todo: init of par.infoptr field in all infotables!!
49 */
50
51 #if defined(PAR) || defined(GRAN)
52
53 # ifdef RBH_MAGIC_OFFSET
54
55 #  error magic offset not yet implemented
56
57 #  define RBH_INFO_WORDS    0
58 #  define INCLUDE_RBH_INFO(infoptr)
59
60 #  define RBH_INFOPTR(infoptr)      (((P_)infoptr) - RBH_MAGIC_OFFSET)
61 #  define REVERT_INFOPTR(infoptr)   (((P_)infoptr) + RBH_MAGIC_OFFSET)
62
63 # else
64
65 #  define RBH_INFO_WORDS    1
66 #  define INCLUDE_RBH_INFO(info)    rbh_infoptr : &(info)
67
68 #  define RBH_INFOPTR(infoptr)      (((StgInfoTable *)(infoptr))->rbh_infoptr)
69 #  define REVERT_INFOPTR(infoptr)   (((StgInfoTable *)(infoptr))->rbh_infoptr)
70
71 # endif
72
73 /* see ParallelRts.h */
74 // EXTFUN(RBH_entry);
75 //StgClosure *convertToRBH(StgClosure *closure);
76 //#if defined(GRAN)
77 //void convertFromRBH(StgClosure *closure);
78 //#elif defined(PAR)
79 //void convertToFetchMe(StgPtr closure, globalAddr *ga);
80 //#endif
81
82 #endif
83
84 /* -----------------------------------------------------------------------------
85    Ticky info
86    -------------------------------------------------------------------------- */
87
88 typedef struct {
89     /* empty */
90 } StgTickyInfo;
91
92 /* -----------------------------------------------------------------------------
93    Debugging info
94    -------------------------------------------------------------------------- */
95
96 #ifdef DEBUG_CLOSURE
97
98 typedef struct {
99         ... whatever ...
100 } StgDebugInfo;
101
102 #else /* !DEBUG_CLOSURE */
103
104 typedef struct {
105         /* empty */
106 } StgDebugInfo;
107
108 #endif /* DEBUG_CLOSURE */
109
110 /* -----------------------------------------------------------------------------
111    Closure flags
112    -------------------------------------------------------------------------- */
113
114 /* The type flags provide quick access to certain properties of a closure. */
115
116 #define _HNF (1<<0)  /* head normal form?    */
117 #define _BTM (1<<1)  /* bitmap-style layout? */
118 #define _NS  (1<<2)  /* non-sparkable        */
119 #define _STA (1<<3)  /* static?              */
120 #define _THU (1<<4)  /* thunk?               */
121 #define _MUT (1<<5)  /* mutable?             */
122 #define _UPT (1<<6)  /* unpointed?           */
123 #define _SRT (1<<7)  /* has an SRT?          */
124 #define _IND (1<<8)  /* is an indirection?   */
125
126 #define isSTATIC(flags)    ((flags) &_STA)
127 #define isMUTABLE(flags)   ((flags) &_MUT)
128 #define isBITMAP(flags)    ((flags) &_BTM)
129 #define isTHUNK(flags)     ((flags) &_THU)
130 #define isUNPOINTED(flags) ((flags) &_UPT)
131 #define hasSRT(flags)      ((flags) &_SRT)
132
133 extern StgWord16 closure_flags[];
134
135 #define closureFlags(c)         (closure_flags[get_itbl(c)->type])
136
137 #define closure_HNF(c)          (  closureFlags(c) & _HNF)
138 #define closure_BITMAP(c)       (  closureFlags(c) & _BTM)
139 #define closure_NON_SPARK(c)    ( (closureFlags(c) & _NS))
140 #define closure_SHOULD_SPARK(c) (!(closureFlags(c) & _NS))
141 #define closure_STATIC(c)       (  closureFlags(c) & _STA)
142 #define closure_THUNK(c)        (  closureFlags(c) & _THU)
143 #define closure_MUTABLE(c)      (  closureFlags(c) & _MUT)
144 #define closure_UNPOINTED(c)    (  closureFlags(c) & _UPT)
145 #define closure_SRT(c)          (  closureFlags(c) & _SRT)
146 #define closure_IND(c)          (  closureFlags(c) & _IND)
147
148 /* same as above but for info-ptr rather than closure */
149 #define ipFlags(ip)             (closure_flags[ip->type])
150
151 #define ip_HNF(ip)               (  ipFlags(ip) & _HNF)
152 #define ip_BITMAP(ip)            (  ipFlags(ip) & _BTM)
153 #define ip_SHOULD_SPARK(ip)      (!(ipFlags(ip) & _NS))
154 #define ip_STATIC(ip)            (  ipFlags(ip) & _STA)
155 #define ip_THUNK(ip)             (  ipFlags(ip) & _THU)
156 #define ip_MUTABLE(ip)           (  ipFlags(ip) & _MUT)
157 #define ip_UNPOINTED(ip)         (  ipFlags(ip) & _UPT)
158 #define ip_SRT(ip)               (  ipFlags(ip) & _SRT)
159 #define ip_IND(ip)               (  ipFlags(ip) & _IND)
160
161 /* -----------------------------------------------------------------------------
162    Bitmaps
163
164    These are used to describe the pointerhood of a sequence of words
165    (usually on the stack) to the garbage collector.  The two primary
166    uses are for stack frames, and functions (where we need to describe
167    the layout of a PAP to the GC).
168    -------------------------------------------------------------------------- */
169
170 //
171 // Small bitmaps:  for a small bitmap, we store the size and bitmap in 
172 // the same word, using the following macros.  If the bitmap doesn't
173 // fit in a single word, we use a pointer to an StgLargeBitmap below.
174 // 
175 #define MK_SMALL_BITMAP(size,bits) (((bits)<<BITMAP_BITS_SHIFT) | (size))
176
177 #define BITMAP_SIZE(bitmap) ((bitmap) & BITMAP_SIZE_MASK)
178 #define BITMAP_BITS(bitmap) ((bitmap) >> BITMAP_BITS_SHIFT)
179
180 //
181 // A large bitmap.
182 //
183 typedef struct {
184   StgWord size;
185   StgWord bitmap[FLEXIBLE_ARRAY];
186 } StgLargeBitmap;
187
188 /* ----------------------------------------------------------------------------
189    Info Tables
190    ------------------------------------------------------------------------- */
191
192 //
193 // Stuff describing the closure layout.  Well, actually, it might
194 // contain the selector index for a THUNK_SELECTOR.  This union is one
195 // word long.
196 //
197 typedef union {
198     struct {                    // Heap closure payload layout:
199         StgHalfWord ptrs;       // number of pointers
200         StgHalfWord nptrs;      // number of non-pointers
201     } payload;
202     
203     StgWord bitmap;               // word-sized bit pattern describing
204                                   //  a stack frame: see below
205
206     StgLargeBitmap* large_bitmap; // pointer to large bitmap structure
207     
208     StgWord selector_offset;      // used in THUNK_SELECTORs
209
210 } StgClosureInfo;
211
212
213 //
214 // An SRT.
215 //
216 typedef StgClosure* StgSRT[];
217
218 //
219 // The "standard" part of an info table.  Every info table has this bit.
220 //
221 typedef struct _StgInfoTable {
222
223 #ifndef TABLES_NEXT_TO_CODE
224     StgFunPtr       entry;      // pointer to the entry code
225 #endif
226
227 #if defined(PAR) || defined(GRAN)
228     struct _StgInfoTable    *rbh_infoptr;
229 #endif
230 #ifdef PROFILING
231     StgProfInfo     prof;
232 #endif
233 #ifdef TICKY
234     StgTickyInfo    ticky;
235 #endif
236 #ifdef DEBUG_CLOSURE
237     StgDebugInfo    debug;
238 #endif
239
240     StgClosureInfo  layout;     // closure layout info (one word)
241
242     StgHalfWord     type;       // closure type
243     StgHalfWord     srt_len;    // number of entries in SRT (or constructor tag)
244
245 #ifdef TABLES_NEXT_TO_CODE
246     StgCode         code[FLEXIBLE_ARRAY];
247 #endif
248 } StgInfoTable;
249
250
251 /* -----------------------------------------------------------------------------
252    Function info tables
253
254    This is the general form of function info tables.  The compiler
255    will omit some of the fields in common cases:
256
257    -  If fun_type is not ARG_GEN or ARG_GEN_BIG, then the slow_apply
258       and bitmap fields may be left out (they are at the end, so omitting
259       them doesn't affect the layout).
260       
261    -  If srt_len (in the std info table part) is zero, then the srt
262       field may be omitted.  This only applies if the slow_apply and
263       bitmap fields have also been omitted.
264    -------------------------------------------------------------------------- */
265
266 typedef struct _StgFunInfoTable {
267 #if defined(TABLES_NEXT_TO_CODE)
268     StgFun         *slow_apply; // apply to args on the stack
269     StgWord        bitmap;      // arg ptr/nonptr bitmap
270     StgSRT         *srt;        // pointer to the SRT table
271     StgHalfWord    fun_type;    // function type
272     StgHalfWord    arity;       // function arity
273     StgInfoTable i;
274 #else
275     StgInfoTable i;
276     StgHalfWord    fun_type;    // function type
277     StgHalfWord    arity;       // function arity
278     StgSRT         *srt;        // pointer to the SRT table
279     StgWord        bitmap;      // arg ptr/nonptr bitmap
280     StgFun         *slow_apply; // apply to args on the stack
281 #endif
282 } StgFunInfoTable;
283
284 /* -----------------------------------------------------------------------------
285    Return info tables
286    -------------------------------------------------------------------------- */
287
288 // When info tables are laid out backwards, we can omit the SRT
289 // pointer iff srt_len is zero.
290
291 typedef struct _StgRetInfoTable {
292 #if !defined(TABLES_NEXT_TO_CODE)
293     StgInfoTable i;
294 #endif
295     StgSRT         *srt;        // pointer to the SRT table
296 #if defined(TABLES_NEXT_TO_CODE)
297     StgInfoTable i;
298 #endif
299 #if !defined(TABLES_NEXT_TO_CODE)
300     StgFunPtr vector[FLEXIBLE_ARRAY];
301 #endif
302 } StgRetInfoTable;
303
304 /* -----------------------------------------------------------------------------
305    Thunk info tables
306    -------------------------------------------------------------------------- */
307
308 // When info tables are laid out backwards, we can omit the SRT
309 // pointer iff srt_len is zero.
310
311 typedef struct _StgThunkInfoTable {
312 #if !defined(TABLES_NEXT_TO_CODE)
313     StgInfoTable i;
314 #endif
315     StgSRT         *srt;        // pointer to the SRT table
316 #if defined(TABLES_NEXT_TO_CODE)
317     StgInfoTable i;
318 #endif
319 } StgThunkInfoTable;
320
321 #endif /* INFOTABLES_H */