[project @ 2000-01-13 14:33:57 by hwloidl]
[ghc-hetmet.git] / ghc / includes / InfoTables.h
1 /* ----------------------------------------------------------------------------
2  * $Id: InfoTables.h,v 1.18 2000/01/13 14:34:00 hwloidl 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 #ifdef PROFILING
18
19 #define PROF_INFO_WORDS n
20
21 typedef struct {
22   /* nothing yet */
23 } StgProfInfo;
24
25 #else /* !PROFILING */
26
27 #define PROF_INFO_WORDS 0
28
29 typedef struct {
30   /* empty */
31 } StgProfInfo;
32
33 #endif /* PROFILING */
34
35 /* -----------------------------------------------------------------------------
36    Parallelism info
37    -------------------------------------------------------------------------- */
38
39 #if 0 && (defined(PAR) || defined(GRAN))
40
41 // CURRENTLY UNUSED
42 // ToDo: use this in StgInfoTable (mutually recursive) -- HWL
43
44 #define PAR_INFO_WORDS 1
45
46 typedef struct {
47   StgInfoTable *rbh_infoptr;     /* infoptr to the RBH  */
48 } StgParInfo;
49
50 #else /* !PAR */
51
52 #define PAR_INFO_WORDS 0
53
54 typedef struct {
55         /* empty */
56 } StgParInfo;
57
58 #endif /* PAR */
59
60 /*
61    Copied from ghc-0.29; ToDo: check this code -- HWL
62
63    In the parallel system, all updatable closures have corresponding
64    revertible black holes.  When we are assembly-mangling, we guarantee
65    that the revertible black hole code precedes the normal entry code, so
66    that the RBH info table resides at a fixed offset from the normal info
67    table.  Otherwise, we add the RBH info table pointer to the end of the
68    normal info table and vice versa.
69
70    Currently has to use a !RBH_MAGIC_OFFSET setting.
71    Still todo: init of par.infoptr field in all infotables!!
72 */
73
74 #if defined(PAR) || defined(GRAN)
75 # define RBH_INFO_OFFSET            (GEN_INFO_OFFSET+GEN_INFO_WORDS)
76
77 # ifdef RBH_MAGIC_OFFSET
78
79 #  error magic offset not yet implemented
80
81 #  define RBH_INFO_WORDS    0
82 #  define INCLUDE_RBH_INFO(infoptr)
83
84 #  define RBH_INFOPTR(infoptr)      (((P_)infoptr) - RBH_MAGIC_OFFSET)
85 #  define REVERT_INFOPTR(infoptr)   (((P_)infoptr) + RBH_MAGIC_OFFSET)
86
87 # else
88
89 #  define RBH_INFO_WORDS    1
90 #  define INCLUDE_RBH_INFO(info)    rbh_infoptr : &(info)
91
92 #  define RBH_INFOPTR(infoptr)      (((StgInfoTable *)(infoptr))->rbh_infoptr)
93 #  define REVERT_INFOPTR(infoptr)   (((StgInfoTable *)(infoptr))->rbh_infoptr)
94
95 # endif
96
97 /* see ParallelRts.h */
98 // EXTFUN(RBH_entry);
99 //StgClosure *convertToRBH(StgClosure *closure);
100 //#if defined(GRAN)
101 //void convertFromRBH(StgClosure *closure);
102 //#elif defined(PAR)
103 //void convertToFetchMe(StgPtr closure, globalAddr *ga);
104 //#endif
105
106 #endif
107
108 /* -----------------------------------------------------------------------------
109    Debugging info
110    -------------------------------------------------------------------------- */
111
112 #ifdef DEBUG_CLOSURE
113
114 #define DEBUG_INFO_WORDS n
115
116 typedef struct {
117         ... whatever ...
118 } StgDebugInfo;
119
120 #else /* !DEBUG_CLOSURE */
121
122 #define DEBUG_INFO_WORDS 0
123
124 typedef struct {
125         /* empty */
126 } StgDebugInfo;
127
128 #endif /* DEBUG_CLOSURE */
129
130 /* The type flags provide quick access to certain properties of a closure. */
131
132 #define _HNF (1<<0)  /* head normal form?  */
133 #define _BTM (1<<1)  /* bitmap-style layout? */
134 #define _NS  (1<<2)  /* non-sparkable      */
135 #define _STA (1<<3)  /* static?            */
136 #define _THU (1<<4)  /* thunk?             */
137 #define _MUT (1<<5)  /* mutable?           */
138 #define _UPT (1<<6)  /* unpointed?         */
139 #define _SRT (1<<7)  /* has an SRT?        */
140
141 #define isSTATIC(flags)    ((flags) &_STA)
142 #define isMUTABLE(flags)   ((flags) &_MUT)
143 #define isBITMAP(flags)    ((flags) &_BTM)
144 #define isTHUNK(flags)     ((flags) &_THU)
145 #define isUNPOINTED(flags) ((flags) &_UPT)
146 #define hasSRT(flags)      ((flags) &_SRT)
147
148 extern StgWord16 closure_flags[];
149
150 #define closureFlags(c)         (closure_flags[get_itbl(c)->type])
151
152 #define closure_HNF(c)          (  closureFlags(c) & _HNF)
153 #define closure_BITMAP(c)       (  closureFlags(c) & _BTM)
154 #define closure_NON_SPARK(c)    ( (closureFlags(c) & _NS))
155 #define closure_SHOULD_SPARK(c) (!(closureFlags(c) & _NS))
156 #define closure_STATIC(c)       (  closureFlags(c) & _STA)
157 #define closure_THUNK(c)        (  closureFlags(c) & _THU)
158 #define closure_MUTABLE(c)      (  closureFlags(c) & _MUT)
159 #define closure_UNPOINTED(c)    (  closureFlags(c) & _UPT)
160 #define closure_SRT(c)          (  closureFlags(c) & _SRT)
161
162 /* same as above but for info-ptr rather than closure */
163 #define ipFlags(ip)             (closure_flags[ip->type])
164
165 #define ip_HNF(ip)               (  ipFlags(ip) & _HNF)
166 #define ip_BITMAP(ip)            (  ipFlags(ip) & _BTM)
167 #define ip_SHOULD_SPARK(ip)      (!(ipFlags(ip) & _NS))
168 #define ip_STATIC(ip)            (  ipFlags(ip) & _STA)
169 #define ip_THUNK(ip)             (  ipFlags(ip) & _THU)
170 #define ip_MUTABLE(ip)           (  ipFlags(ip) & _MUT)
171 #define ip_UNPOINTED(ip)         (  ipFlags(ip) & _UPT)
172 #define ip_SRT(ip)               (  ipFlags(ip) & _SRT)
173
174 /* -----------------------------------------------------------------------------
175    Info Tables
176    -------------------------------------------------------------------------- */
177
178 /* A large bitmap.  Small 32-bit ones live in the info table, but sometimes
179  * 32 bits isn't enough and we have to generate a larger one.  (sizes
180  * differ for 64-bit machines.
181  */
182
183 typedef struct {
184   StgWord size;
185   StgWord bitmap[0];
186 } StgLargeBitmap;
187
188 /*
189  * Stuff describing the closure layout.  Well, actually, it might
190  * contain the selector index for a THUNK_SELECTOR.  If we're on a
191  * 64-bit architecture then we can enlarge some of these fields, since
192  * the union contains a pointer field.
193  */
194
195 typedef union {
196   struct {
197 #if SIZEOF_VOID_P == 8
198     StgWord32 ptrs;             /* number of pointers     */
199     StgWord32 nptrs;            /* number of non-pointers */
200 #else
201     StgWord16 ptrs;             /* number of pointers     */
202     StgWord16 nptrs;            /* number of non-pointers */
203 #endif
204   } payload;
205
206   StgWord bitmap;               /* bit pattern, 1 = pointer, 0 = non-pointer */
207   StgWord selector_offset;      /* used in THUNK_SELECTORs */
208   StgLargeBitmap* large_bitmap; /* pointer to large bitmap structure */
209   
210 } StgClosureInfo;
211
212 /*
213  * Info tables.  All info tables are the same type, to simplify code
214  * generation.  However, the mangler removes any unused SRT fields
215  * from the asm to save space (convention: if srt_len is zero, or the
216  * type is a CONSTR_ type, then the SRT field isn't present.
217  */
218
219 typedef StgClosure* StgSRT[];
220
221 typedef struct _StgInfoTable {
222     StgSRT         *srt;        /* pointer to the SRT table */
223 #if defined(PAR) || defined(GRAN)
224   // StgParInfo     par;
225     struct _StgInfoTable    *rbh_infoptr;
226 #endif
227 #ifdef PROFILING
228   /* StgProfInfo     prof; */
229 #endif
230 #ifdef DEBUG_CLOSURE
231     StgDebugInfo    debug;
232 #endif
233     StgClosureInfo  layout;     /* closure layout info (pointer-sized) */
234 #if SIZEOF_VOID_P == 8
235     StgWord32       type;       /* } These 2 elements fit into 64 bits */
236     StgWord32       srt_len;    /* }                                   */
237 #else
238     StgWord         type : 16;  /* } These 2 elements fit into 32 bits */
239     StgWord         srt_len : 16; /* }                                   */
240 #endif
241 #ifdef TABLES_NEXT_TO_CODE
242     StgCode         code[0];
243 #else
244     StgFunPtr       entry;
245     StgFunPtr       vector[0];
246 #endif
247 } StgInfoTable;
248
249 /* Info tables are read-only, therefore we uniformly declare them with
250  * C's const attribute.  This isn't just a nice thing to do: it's
251  * necessary because the garbage collector has to distinguish between 
252  * closure pointers and info table pointers when traversing the
253  * stack.  We distinguish the two by checking whether the pointer is
254  * into text-space or not.
255  */
256  
257 #define INFO_TBL_CONST  const
258
259 #endif /* INFOTABLES_H */