[project @ 2002-01-29 16:50:08 by simonmar]
[ghc-hetmet.git] / ghc / includes / InfoTables.h
1 /* ----------------------------------------------------------------------------
2  * $Id: InfoTables.h,v 1.25 2002/01/29 16:50:08 simonmar Exp $
3  * 
4  * (c) The GHC Team, 1998-1999
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 /* The type flags provide quick access to certain properties of a closure. */
111
112 #define _HNF (1<<0)  /* head normal form?    */
113 #define _BTM (1<<1)  /* bitmap-style layout? */
114 #define _NS  (1<<2)  /* non-sparkable        */
115 #define _STA (1<<3)  /* static?              */
116 #define _THU (1<<4)  /* thunk?               */
117 #define _MUT (1<<5)  /* mutable?             */
118 #define _UPT (1<<6)  /* unpointed?           */
119 #define _SRT (1<<7)  /* has an SRT?          */
120 #define _IND (1<<8)  /* is an indirection?   */
121
122 #define isSTATIC(flags)    ((flags) &_STA)
123 #define isMUTABLE(flags)   ((flags) &_MUT)
124 #define isBITMAP(flags)    ((flags) &_BTM)
125 #define isTHUNK(flags)     ((flags) &_THU)
126 #define isUNPOINTED(flags) ((flags) &_UPT)
127 #define hasSRT(flags)      ((flags) &_SRT)
128
129 extern StgWord16 closure_flags[];
130
131 #define closureFlags(c)         (closure_flags[get_itbl(c)->type])
132
133 #define closure_HNF(c)          (  closureFlags(c) & _HNF)
134 #define closure_BITMAP(c)       (  closureFlags(c) & _BTM)
135 #define closure_NON_SPARK(c)    ( (closureFlags(c) & _NS))
136 #define closure_SHOULD_SPARK(c) (!(closureFlags(c) & _NS))
137 #define closure_STATIC(c)       (  closureFlags(c) & _STA)
138 #define closure_THUNK(c)        (  closureFlags(c) & _THU)
139 #define closure_MUTABLE(c)      (  closureFlags(c) & _MUT)
140 #define closure_UNPOINTED(c)    (  closureFlags(c) & _UPT)
141 #define closure_SRT(c)          (  closureFlags(c) & _SRT)
142 #define closure_IND(c)          (  closureFlags(c) & _IND)
143
144 /* same as above but for info-ptr rather than closure */
145 #define ipFlags(ip)             (closure_flags[ip->type])
146
147 #define ip_HNF(ip)               (  ipFlags(ip) & _HNF)
148 #define ip_BITMAP(ip)            (  ipFlags(ip) & _BTM)
149 #define ip_SHOULD_SPARK(ip)      (!(ipFlags(ip) & _NS))
150 #define ip_STATIC(ip)            (  ipFlags(ip) & _STA)
151 #define ip_THUNK(ip)             (  ipFlags(ip) & _THU)
152 #define ip_MUTABLE(ip)           (  ipFlags(ip) & _MUT)
153 #define ip_UNPOINTED(ip)         (  ipFlags(ip) & _UPT)
154 #define ip_SRT(ip)               (  ipFlags(ip) & _SRT)
155 #define ip_IND(ip)               (  ipFlags(ip) & _IND)
156
157 /* -----------------------------------------------------------------------------
158    Info Tables
159    -------------------------------------------------------------------------- */
160
161 /* A large bitmap.  Small 32-bit ones live in the info table, but sometimes
162  * 32 bits isn't enough and we have to generate a larger one.  (sizes
163  * differ for 64-bit machines.
164  */
165
166 typedef struct {
167   StgWord size;
168   StgWord bitmap[FLEXIBLE_ARRAY];
169 } StgLargeBitmap;
170
171 /*
172  * Stuff describing the closure layout.  Well, actually, it might
173  * contain the selector index for a THUNK_SELECTOR.  If we're on a
174  * 64-bit architecture then we can enlarge some of these fields, since
175  * the union contains a pointer field.
176  */
177
178 typedef union {
179   struct {
180 #if SIZEOF_VOID_P == 8
181     StgWord32 ptrs;             /* number of pointers     */
182     StgWord32 nptrs;            /* number of non-pointers */
183 #else
184     StgWord16 ptrs;             /* number of pointers     */
185     StgWord16 nptrs;            /* number of non-pointers */
186 #endif
187   } payload;
188
189   StgWord bitmap;               /* bit pattern, 1 = pointer, 0 = non-pointer */
190   StgWord selector_offset;      /* used in THUNK_SELECTORs */
191   StgLargeBitmap* large_bitmap; /* pointer to large bitmap structure */
192   
193 } StgClosureInfo;
194
195 /*
196  * Info tables.  All info tables are the same type, to simplify code
197  * generation.  However, the mangler removes any unused SRT fields
198  * from the asm to save space (convention: if srt_len is zero, or the
199  * type is a CONSTR_ type, then the SRT field isn't present.
200  */
201
202 typedef StgClosure* StgSRT[];
203
204 /*
205  * The entry code pointer must be the first word of an info table.
206  * See the comment in ghc/rts/Storage.h (Plan C) for details.
207  */
208 typedef struct _StgInfoTable {
209 #ifndef TABLES_NEXT_TO_CODE
210     StgFunPtr       entry;
211 #endif
212     StgSRT         *srt;        /* pointer to the SRT table */
213 #if defined(PAR) || defined(GRAN)
214     struct _StgInfoTable    *rbh_infoptr;
215 #endif
216 #ifdef PROFILING
217     StgProfInfo     prof;
218 #endif
219 #ifdef TICKY
220     StgTickyInfo    ticky;
221 #endif
222 #ifdef DEBUG_CLOSURE
223     StgDebugInfo    debug;
224 #endif
225     StgClosureInfo  layout;     /* closure layout info (pointer-sized) */
226 #if SIZEOF_VOID_P == 8
227     StgWord32       type;       /* } These 2 elements fit into 64 bits */
228     StgWord32       srt_len;    /* }                                   */
229 #else
230     StgWord         type : 16;  /* } These 2 elements fit into 32 bits */
231     StgWord         srt_len : 16; /* }                                   */
232 #endif
233 #ifdef TABLES_NEXT_TO_CODE
234     StgCode         code[FLEXIBLE_ARRAY];
235 #else
236     StgFunPtr       vector[FLEXIBLE_ARRAY];
237 #endif
238 } StgInfoTable;
239
240 /* Info tables are read-only, therefore we uniformly declare them with
241  * C's const attribute.  This isn't just a nice thing to do: it's
242  * necessary because the garbage collector has to distinguish between 
243  * closure pointers and info table pointers when traversing the
244  * stack.  We distinguish the two by checking whether the pointer is
245  * into text-space or not.
246  */
247  
248 #define INFO_TBL_CONST  const
249
250 #endif /* INFOTABLES_H */