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