Improve hierarchical module name handling in MkExternalCore
[ghc-hetmet.git] / includes / Cmm.h
1 /* -----------------------------------------------------------------------------
2  *
3  * (c) The University of Glasgow 2004
4  *
5  * This file is included at the top of all .cmm source files (and
6  * *only* .cmm files).  It defines a collection of useful macros for
7  * making .cmm code a bit less error-prone to write, and a bit easier
8  * on the eye for the reader.
9  *
10  * For the syntax of .cmm files, see the parser in ghc/compiler/cmm/CmmParse.y.
11  *
12  * If you're used to the old HC file syntax, here's a quick cheat sheet
13  * for converting HC code:
14  *
15  *       - Remove FB_/FE_
16  *       - Remove all type casts
17  *       - Remove '&'
18  *       - STGFUN(foo) { ... }  ==>  foo { ... }
19  *       - FN_(foo) { ... }  ==>  foo { ... }
20  *       - JMP_(e)  ==> jump e;
21  *       - Remove EXTFUN(foo)
22  *       - Sp[n]  ==>  Sp(n)
23  *       - Hp[n]  ==>  Hp(n)
24  *       - Sp += n  ==> Sp_adj(n)
25  *       - Hp += n  ==> Hp_adj(n)
26  *       - R1.i   ==>  R1   (similarly for R1.w, R1.cl etc.)
27  *       - You need to explicitly dereference variables; eg. 
28  *             context_switch   ==>  CInt[context_switch]
29  *       - convert all word offsets into byte offsets:
30  *              - e ==> WDS(e)
31  *       - sizeofW(StgFoo)  ==>  SIZEOF_StgFoo
32  *       - ENTRY_CODE(e)  ==>  %ENTRY_CODE(e)
33  *       - get_itbl(c)  ==>  %GET_STD_INFO(c)
34  *       - Change liveness masks in STK_CHK_GEN, HP_CHK_GEN:
35  *              R1_PTR | R2_PTR  ==>  R1_PTR & R2_PTR
36  *              (NOTE: | becomes &)
37  *       - Declarations like 'StgPtr p;' become just 'W_ p;'
38  *       - e->payload[n] ==> PAYLOAD(e,n)
39  *       - Be very careful with comparisons: the infix versions (>, >=, etc.)
40  *         are unsigned, so use %lt(a,b) to get signed less-than for example.
41  *
42  * Accessing fields of structures defined in the RTS header files is
43  * done via automatically-generated macros in DerivedConstants.h.  For
44  * example, where previously we used
45  *
46  *          CurrentTSO->what_next = x
47  *
48  * in C-- we now use
49  *
50  *          StgTSO_what_next(CurrentTSO) = x
51  *
52  * where the StgTSO_what_next() macro is automatically generated by
53  * mkDerivedConstnants.c.  If you need to access a field that doesn't
54  * already have a macro, edit that file (it's pretty self-explanatory).
55  *
56  * -------------------------------------------------------------------------- */
57
58 #ifndef CMM_H
59 #define CMM_H
60
61 /*
62  * In files that are included into both C and C-- (and perhaps
63  * Haskell) sources, we sometimes need to conditionally compile bits
64  * depending on the language.  CMINUSMINUS==1 in .cmm sources:
65  */
66 #define CMINUSMINUS 1
67
68 #include "ghcconfig.h"
69 #include "RtsConfig.h"
70
71 /* -----------------------------------------------------------------------------
72    Types 
73
74    The following synonyms for C-- types are declared here:
75
76      I8, I16, I32, I64    MachRep-style names for convenience
77
78      W_                   is shorthand for the word type (== StgWord)
79      F_                   shorthand for float  (F_ == StgFloat == C's float)
80      D_                   shorthand for double (D_ == StgDouble == C's double)
81
82      CInt                 has the same size as an int in C on this platform
83      CLong                has the same size as a long in C on this platform
84    
85   --------------------------------------------------------------------------- */
86
87 #define I8  bits8
88 #define I16 bits16
89 #define I32 bits32
90 #define I64 bits64
91
92 #if SIZEOF_VOID_P == 4
93 #define W_ bits32
94 /* Maybe it's better to include MachDeps.h */
95 #define TAG_BITS                2
96 #elif SIZEOF_VOID_P == 8
97 #define W_ bits64
98 /* Maybe it's better to include MachDeps.h */
99 #define TAG_BITS                3
100 #else
101 #error Unknown word size
102 #endif
103
104 /*
105  * The RTS must UNTAG a pointer before dereferencing it.
106  * The use of UNTAG follows the following rules of thumb:
107  *
108  * - Any pointer might be tagged.
109  * - Except the pointers that are passed in R1 to RTS functions.
110  * - R1 is also untagged when entering constructor code.
111  * 
112  * TODO:
113  *
114  * - Remove redundancies of tagging and untagging in code generation.
115  * - Optimize getTag or dataToTag# ?
116  *
117  */
118 #define TAG_MASK ((1 << TAG_BITS) - 1)
119 #define UNTAG(p) (p & ~TAG_MASK)
120 #define GETTAG(p) (p & TAG_MASK)
121
122 #if SIZEOF_INT == 4
123 #define CInt bits32
124 #elif SIZEOF_INT == 8
125 #define CInt bits64
126 #else
127 #error Unknown int size
128 #endif
129
130 #if SIZEOF_LONG == 4
131 #define CLong bits32
132 #elif SIZEOF_LONG == 8
133 #define CLong bits64
134 #else
135 #error Unknown long size
136 #endif
137
138 #define F_ float32
139 #define D_ float64
140 #define L_ bits64
141
142 #define SIZEOF_StgDouble 8
143 #define SIZEOF_StgWord64 8
144
145 /* -----------------------------------------------------------------------------
146    Misc useful stuff
147    -------------------------------------------------------------------------- */
148
149 #define NULL (0::W_)
150
151 #define STRING(name,str)                        \
152   section "rodata" {                            \
153         name : bits8[] str;                     \
154   }                                             \
155
156 /* -----------------------------------------------------------------------------
157    Byte/word macros
158
159    Everything in C-- is in byte offsets (well, most things).  We use
160    some macros to allow us to express offsets in words and to try to
161    avoid byte/word confusion.
162    -------------------------------------------------------------------------- */
163
164 #define SIZEOF_W  SIZEOF_VOID_P
165 #define W_MASK    (SIZEOF_W-1)
166
167 #if SIZEOF_W == 4
168 #define W_SHIFT 2
169 #elif SIZEOF_W == 8
170 #define W_SHIFT 4
171 #endif
172
173 /* Converting quantities of words to bytes */
174 #define WDS(n) ((n)*SIZEOF_W)
175
176 /*
177  * Converting quantities of bytes to words
178  * NB. these work on *unsigned* values only
179  */
180 #define BYTES_TO_WDS(n) ((n) / SIZEOF_W)
181 #define ROUNDUP_BYTES_TO_WDS(n) (((n) + SIZEOF_W - 1) / SIZEOF_W)
182
183 /* TO_W_(n) converts n to W_ type from a smaller type */
184 #if SIZEOF_W == 4
185 #define TO_W_(x) %sx32(x)
186 #define HALF_W_(x) %lobits16(x)
187 #elif SIZEOF_W == 8
188 #define TO_W_(x) %sx64(x)
189 #define HALF_W_(x) %lobits32(x)
190 #endif
191
192 #if SIZEOF_INT == 4 && SIZEOF_W == 8
193 #define W_TO_INT(x) %lobits32(x)
194 #elif SIZEOF_INT == SIZEOF_W
195 #define W_TO_INT(x) (x)
196 #endif
197
198 /* -----------------------------------------------------------------------------
199    Heap/stack access, and adjusting the heap/stack pointers.
200    -------------------------------------------------------------------------- */
201
202 #define Sp(n)  W_[Sp + WDS(n)]
203 #define Hp(n)  W_[Hp + WDS(n)]
204
205 #define Sp_adj(n) Sp = Sp + WDS(n)
206 #define Hp_adj(n) Hp = Hp + WDS(n)
207
208 /* -----------------------------------------------------------------------------
209    Assertions and Debuggery
210    -------------------------------------------------------------------------- */
211
212 #ifdef DEBUG
213 #define ASSERT(predicate)                       \
214         if (predicate) {                        \
215             /*null*/;                           \
216         } else {                                \
217             foreign "C" _assertFail(NULL, __LINE__); \
218         }
219 #else
220 #define ASSERT(p) /* nothing */
221 #endif
222
223 #ifdef DEBUG
224 #define DEBUG_ONLY(s) s
225 #else
226 #define DEBUG_ONLY(s) /* nothing */
227 #endif
228
229 /*
230  * The IF_DEBUG macro is useful for debug messages that depend on one
231  * of the RTS debug options.  For example:
232  * 
233  *   IF_DEBUG(RtsFlags_DebugFlags_apply,
234  *      foreign "C" fprintf(stderr, stg_ap_0_ret_str));
235  *
236  * Note the syntax is slightly different to the C version of this macro.
237  */
238 #ifdef DEBUG
239 #define IF_DEBUG(c,s)  if (RtsFlags_DebugFlags_##c(RtsFlags) != 0::I32) { s; }
240 #else
241 #define IF_DEBUG(c,s)  /* nothing */
242 #endif
243
244 /* -----------------------------------------------------------------------------
245    Entering 
246
247    It isn't safe to "enter" every closure.  Functions in particular
248    have no entry code as such; their entry point contains the code to
249    apply the function.
250
251    ToDo: range should end in N_CLOSURE_TYPES-1, not N_CLOSURE_TYPES,
252    but switch doesn't allow us to use exprs there yet.
253
254    If R1 points to a tagged object it points either to
255    * A constructor.
256    * A function with arity <= TAG_MASK.
257    In both cases the right thing to do is to return.
258    Note: it is rather lucky that we can use the tag bits to do this
259          for both objects. Maybe it points to a brittle design?
260
261    Indirections can contain tagged pointers, so their tag is checked.
262    -------------------------------------------------------------------------- */
263
264 #define ENTER()                                         \
265  again:                                                 \
266   W_ info;                                              \
267   if (GETTAG(R1) != 0) {                                \
268       jump %ENTRY_CODE(Sp(0));                          \
269   }                                                     \
270   info = %INFO_PTR(R1);                                 \
271   switch [INVALID_OBJECT .. N_CLOSURE_TYPES]            \
272          (TO_W_( %INFO_TYPE(%STD_INFO(info)) )) {       \
273   case                                                  \
274     IND,                                                \
275     IND_OLDGEN,                                         \
276     IND_PERM,                                           \
277     IND_OLDGEN_PERM,                                    \
278     IND_STATIC:                                         \
279    {                                                    \
280       R1 = StgInd_indirectee(R1);                       \
281       goto again;                                       \
282    }                                                    \
283   case                                                  \
284     FUN,                                                \
285     FUN_1_0,                                            \
286     FUN_0_1,                                            \
287     FUN_2_0,                                            \
288     FUN_1_1,                                            \
289     FUN_STATIC,                                         \
290     BCO,                                                \
291     PAP:                                                \
292    {                                                    \
293       jump %ENTRY_CODE(Sp(0));                          \
294    }                                                    \
295   default:                                              \
296    {                                                    \
297       jump %ENTRY_CODE(info);                           \
298    }                                                    \
299   }
300
301 // The FUN cases almost never happen: a pointer to a non-static FUN
302 // should always be tagged.  This unfortunately isn't true for the
303 // interpreter right now, which leaves untagged FUNs on the stack.
304
305 /* -----------------------------------------------------------------------------
306    Constants.
307    -------------------------------------------------------------------------- */
308
309 #include "Constants.h"
310 #include "DerivedConstants.h"
311 #include "ClosureTypes.h"
312 #include "StgFun.h"
313 #include "OSThreads.h"
314 #include "SMP.h"
315
316 /*
317  * Need MachRegs, because some of the RTS code is conditionally
318  * compiled based on REG_R1, REG_R2, etc.
319  */
320 #define STOLEN_X86_REGS 4
321 #include "MachRegs.h"
322
323 #include "Liveness.h"
324 #include "StgLdvProf.h"
325
326 #undef BLOCK_SIZE
327 #undef MBLOCK_SIZE
328 #include "Block.h"  /* For Bdescr() */
329
330
331 /* Can't think of a better place to put this. */
332 #if SIZEOF_mp_limb_t != SIZEOF_VOID_P
333 #error mp_limb_t != StgWord: assumptions in PrimOps.cmm are now false
334 #endif
335
336 #define MyCapability()  (BaseReg - OFFSET_Capability_r)
337
338 /* -------------------------------------------------------------------------
339    Allocation and garbage collection
340    ------------------------------------------------------------------------- */
341
342 /*
343  * ALLOC_PRIM is for allocating memory on the heap for a primitive
344  * object.  It is used all over PrimOps.cmm.
345  *
346  * We make the simplifying assumption that the "admin" part of a
347  * primitive closure is just the header when calculating sizes for
348  * ticky-ticky.  It's not clear whether eg. the size field of an array
349  * should be counted as "admin", or the various fields of a BCO.
350  */
351 #define ALLOC_PRIM(bytes,liveness,reentry)                      \
352    HP_CHK_GEN_TICKY(bytes,liveness,reentry);                    \
353    TICK_ALLOC_PRIM(SIZEOF_StgHeader,bytes-SIZEOF_StgHeader,0);  \
354    CCCS_ALLOC(bytes);
355
356 /* CCS_ALLOC wants the size in words, because ccs->mem_alloc is in words */
357 #define CCCS_ALLOC(__alloc) CCS_ALLOC(BYTES_TO_WDS(__alloc), W_[CCCS])
358
359 #define HP_CHK_GEN_TICKY(alloc,liveness,reentry)        \
360    HP_CHK_GEN(alloc,liveness,reentry);                  \
361    TICK_ALLOC_HEAP_NOCTR(alloc);
362
363 // allocateLocal() allocates from the nursery, so we check to see
364 // whether the nursery is nearly empty in any function that uses
365 // allocateLocal() - this includes many of the primops.
366 #define MAYBE_GC(liveness,reentry)                      \
367   if (bdescr_link(CurrentNursery) == NULL || CInt[alloc_blocks] >= CInt[alloc_blocks_lim]) {            \
368         R9  = liveness;                                 \
369         R10 = reentry;                                  \
370         HpAlloc = 0;                                    \
371         jump stg_gc_gen_hp;                             \
372    }
373
374 /* -----------------------------------------------------------------------------
375    Closure headers
376    -------------------------------------------------------------------------- */
377
378 /*
379  * This is really ugly, since we don't do the rest of StgHeader this
380  * way.  The problem is that values from DerivedConstants.h cannot be 
381  * dependent on the way (SMP, PROF etc.).  For SIZEOF_StgHeader we get
382  * the value from GHC, but it seems like too much trouble to do that
383  * for StgThunkHeader.
384  */
385 #define SIZEOF_StgThunkHeader SIZEOF_StgHeader+SIZEOF_StgSMPThunkHeader
386
387 #define StgThunk_payload(__ptr__,__ix__) \
388     W_[__ptr__+SIZEOF_StgThunkHeader+ WDS(__ix__)]
389
390 /* -----------------------------------------------------------------------------
391    Closures
392    -------------------------------------------------------------------------- */
393
394 /* The offset of the payload of an array */
395 #define BYTE_ARR_CTS(arr)  ((arr) + SIZEOF_StgArrWords)
396
397 /* Getting/setting the info pointer of a closure */
398 #define SET_INFO(p,info) StgHeader_info(p) = info
399 #define GET_INFO(p) StgHeader_info(p)
400
401 /* Determine the size of an ordinary closure from its info table */
402 #define sizeW_fromITBL(itbl) \
403   SIZEOF_StgHeader + WDS(%INFO_PTRS(itbl)) + WDS(%INFO_NPTRS(itbl))
404
405 /* NB. duplicated from InfoTables.h! */
406 #define BITMAP_SIZE(bitmap) ((bitmap) & BITMAP_SIZE_MASK)
407 #define BITMAP_BITS(bitmap) ((bitmap) >> BITMAP_BITS_SHIFT)
408
409 /* Debugging macros */
410 #define LOOKS_LIKE_INFO_PTR(p)                          \
411    ((p) != NULL &&                                      \
412      (TO_W_(%INFO_TYPE(%STD_INFO(p))) != INVALID_OBJECT) &&     \
413      (TO_W_(%INFO_TYPE(%STD_INFO(p))) <  N_CLOSURE_TYPES))
414
415 #define LOOKS_LIKE_CLOSURE_PTR(p) (LOOKS_LIKE_INFO_PTR(GET_INFO(UNTAG(p))))
416
417 /*
418  * The layout of the StgFunInfoExtra part of an info table changes
419  * depending on TABLES_NEXT_TO_CODE.  So we define field access
420  * macros which use the appropriate version here:
421  */
422 #ifdef TABLES_NEXT_TO_CODE
423 /*
424  * when TABLES_NEXT_TO_CODE, slow_apply is stored as an offset
425  * instead of the normal pointer.
426  */
427         
428 #define StgFunInfoExtra_slow_apply(fun_info)    \
429         (TO_W_(StgFunInfoExtraRev_slow_apply_offset(fun_info))    \
430                + (fun_info) + SIZEOF_StgFunInfoExtraRev + SIZEOF_StgInfoTable)
431
432 #define StgFunInfoExtra_fun_type(i)   StgFunInfoExtraRev_fun_type(i)
433 #define StgFunInfoExtra_arity(i)      StgFunInfoExtraRev_arity(i)
434 #define StgFunInfoExtra_bitmap(i)     StgFunInfoExtraRev_bitmap(i)
435 #else
436 #define StgFunInfoExtra_slow_apply(i) StgFunInfoExtraFwd_slow_apply(i)
437 #define StgFunInfoExtra_fun_type(i)   StgFunInfoExtraFwd_fun_type(i)
438 #define StgFunInfoExtra_arity(i)      StgFunInfoExtraFwd_arity(i)
439 #define StgFunInfoExtra_bitmap(i)     StgFunInfoExtraFwd_bitmap(i)
440 #endif
441
442 /* -----------------------------------------------------------------------------
443    Voluntary Yields/Blocks
444
445    We only have a generic version of this at the moment - if it turns
446    out to be slowing us down we can make specialised ones.
447    -------------------------------------------------------------------------- */
448
449 #define YIELD(liveness,reentry)                 \
450    R9  = liveness;                              \
451    R10 = reentry;                               \
452    jump stg_gen_yield;
453
454 #define BLOCK(liveness,reentry)                 \
455    R9  = liveness;                              \
456    R10 = reentry;                               \
457    jump stg_gen_block;
458
459 /* -----------------------------------------------------------------------------
460    Ticky macros 
461    -------------------------------------------------------------------------- */
462
463 #ifdef TICKY_TICKY
464 #define TICK_BUMP_BY(ctr,n) CLong[ctr] = CLong[ctr] + n
465 #else
466 #define TICK_BUMP_BY(ctr,n) /* nothing */
467 #endif
468
469 #define TICK_BUMP(ctr)      TICK_BUMP_BY(ctr,1)
470
471 #define TICK_ENT_DYN_IND()              TICK_BUMP(ENT_DYN_IND_ctr)
472 #define TICK_ENT_DYN_THK()              TICK_BUMP(ENT_DYN_THK_ctr)
473 #define TICK_ENT_VIA_NODE()             TICK_BUMP(ENT_VIA_NODE_ctr)
474 #define TICK_ENT_STATIC_IND()           TICK_BUMP(ENT_STATIC_IND_ctr)
475 #define TICK_ENT_PERM_IND()             TICK_BUMP(ENT_PERM_IND_ctr)
476 #define TICK_ENT_PAP()                  TICK_BUMP(ENT_PAP_ctr)
477 #define TICK_ENT_AP()                   TICK_BUMP(ENT_AP_ctr)
478 #define TICK_ENT_AP_STACK()             TICK_BUMP(ENT_AP_STACK_ctr)
479 #define TICK_ENT_BH()                   TICK_BUMP(ENT_BH_ctr)
480 #define TICK_UNKNOWN_CALL()             TICK_BUMP(UNKNOWN_CALL_ctr)
481 #define TICK_UPDF_PUSHED()              TICK_BUMP(UPDF_PUSHED_ctr)
482 #define TICK_CATCHF_PUSHED()            TICK_BUMP(CATCHF_PUSHED_ctr)
483 #define TICK_UPDF_OMITTED()             TICK_BUMP(UPDF_OMITTED_ctr)
484 #define TICK_UPD_NEW_IND()              TICK_BUMP(UPD_NEW_IND_ctr)
485 #define TICK_UPD_NEW_PERM_IND()         TICK_BUMP(UPD_NEW_PERM_IND_ctr)
486 #define TICK_UPD_OLD_IND()              TICK_BUMP(UPD_OLD_IND_ctr)
487 #define TICK_UPD_OLD_PERM_IND()         TICK_BUMP(UPD_OLD_PERM_IND_ctr)
488   
489 #define TICK_SLOW_CALL_FUN_TOO_FEW()    TICK_BUMP(SLOW_CALL_FUN_TOO_FEW_ctr)
490 #define TICK_SLOW_CALL_FUN_CORRECT()    TICK_BUMP(SLOW_CALL_FUN_CORRECT_ctr)
491 #define TICK_SLOW_CALL_FUN_TOO_MANY()   TICK_BUMP(SLOW_CALL_FUN_TOO_MANY_ctr)
492 #define TICK_SLOW_CALL_PAP_TOO_FEW()    TICK_BUMP(SLOW_CALL_PAP_TOO_FEW_ctr)
493 #define TICK_SLOW_CALL_PAP_CORRECT()    TICK_BUMP(SLOW_CALL_PAP_CORRECT_ctr)
494 #define TICK_SLOW_CALL_PAP_TOO_MANY()   TICK_BUMP(SLOW_CALL_PAP_TOO_MANY_ctr)
495
496 #define TICK_SLOW_CALL_v()              TICK_BUMP(SLOW_CALL_v_ctr)
497 #define TICK_SLOW_CALL_p()              TICK_BUMP(SLOW_CALL_p_ctr)
498 #define TICK_SLOW_CALL_pv()             TICK_BUMP(SLOW_CALL_pv_ctr)
499 #define TICK_SLOW_CALL_pp()             TICK_BUMP(SLOW_CALL_pp_ctr)
500 #define TICK_SLOW_CALL_ppp()            TICK_BUMP(SLOW_CALL_ppp_ctr)
501 #define TICK_SLOW_CALL_pppp()           TICK_BUMP(SLOW_CALL_pppp_ctr)
502 #define TICK_SLOW_CALL_ppppp()          TICK_BUMP(SLOW_CALL_ppppp_ctr)
503 #define TICK_SLOW_CALL_pppppp()         TICK_BUMP(SLOW_CALL_pppppp_ctr)
504
505 /* NOTE: TICK_HISTO_BY and TICK_HISTO 
506    currently have no effect.
507    The old code for it didn't typecheck and I 
508    just commented it out to get ticky to work.
509    - krc 1/2007 */
510
511 #define TICK_HISTO_BY(histo,n,i) /* nothing */
512
513 #define TICK_HISTO(histo,n) TICK_HISTO_BY(histo,n,1)
514
515 /* An unboxed tuple with n components. */
516 #define TICK_RET_UNBOXED_TUP(n)                 \
517   TICK_BUMP(RET_UNBOXED_TUP_ctr++);             \
518   TICK_HISTO(RET_UNBOXED_TUP,n)
519
520 /*
521  * A slow call with n arguments.  In the unevald case, this call has
522  * already been counted once, so don't count it again.
523  */
524 #define TICK_SLOW_CALL(n)                       \
525   TICK_BUMP(SLOW_CALL_ctr);                     \
526   TICK_HISTO(SLOW_CALL,n)
527
528 /*
529  * This slow call was found to be to an unevaluated function; undo the
530  * ticks we did in TICK_SLOW_CALL.
531  */
532 #define TICK_SLOW_CALL_UNEVALD(n)               \
533   TICK_BUMP(SLOW_CALL_UNEVALD_ctr);             \
534   TICK_BUMP_BY(SLOW_CALL_ctr,-1);               \
535   TICK_HISTO_BY(SLOW_CALL,n,-1);
536
537 /* Updating a closure with a new CON */
538 #define TICK_UPD_CON_IN_NEW(n)                  \
539   TICK_BUMP(UPD_CON_IN_NEW_ctr);                \
540   TICK_HISTO(UPD_CON_IN_NEW,n)
541
542 #define TICK_ALLOC_HEAP_NOCTR(n)                \
543     TICK_BUMP(ALLOC_HEAP_ctr);                  \
544     TICK_BUMP_BY(ALLOC_HEAP_tot,n)
545
546 /* -----------------------------------------------------------------------------
547    Misc junk
548    -------------------------------------------------------------------------- */
549
550 #define NO_TREC                   stg_NO_TREC_closure
551 #define END_TSO_QUEUE             stg_END_TSO_QUEUE_closure
552 #define END_INVARIANT_CHECK_QUEUE stg_END_INVARIANT_CHECK_QUEUE_closure
553
554 #define dirtyTSO(tso) \
555     StgTSO_flags(tso) = StgTSO_flags(tso) | TSO_DIRTY::I32;
556
557 #define recordMutableCap(p, gen, regs)                                  \
558   W_ __bd;                                                              \
559   W_ mut_list;                                                          \
560   mut_list = Capability_mut_lists(MyCapability()) + WDS(gen);           \
561  __bd = W_[mut_list];                                                   \
562   if (bdescr_free(__bd) >= bdescr_start(__bd) + BLOCK_SIZE) {           \
563       W_ __new_bd;                                                      \
564       ("ptr" __new_bd) = foreign "C" allocBlock_lock() [regs];          \
565       bdescr_link(__new_bd) = __bd;                                     \
566       __bd = __new_bd;                                                  \
567       W_[mut_list] = __bd;                                              \
568   }                                                                     \
569   W_ free;                                                              \
570   free = bdescr_free(__bd);                                             \
571   W_[free] = p;                                                         \
572   bdescr_free(__bd) = free + WDS(1);
573
574 #define recordMutable(p, regs)                                  \
575       W_ __p;                                                   \
576       W_ __bd;                                                  \
577       W_ __gen;                                                 \
578       __p = p;                                                  \
579       __bd = Bdescr(__p);                                       \
580       __gen = TO_W_(bdescr_gen_no(__bd));                       \
581       if (__gen > 0) { recordMutableCap(__p, __gen, regs); }
582
583 #endif /* CMM_H */