[project @ 2004-02-12 02:04:59 by mthomas]
[ghc-hetmet.git] / ghc / includes / StgLdvProf.h
1 /* -----------------------------------------------------------------------------
2  * $Id: StgLdvProf.h,v 1.2 2001/11/26 16:54:22 simonmar Exp $
3  *
4  * (c) The GHC Team, 2001
5  * Author: Sungwoo Park
6  *
7  * Lag/Drag/Void profiling.
8  *
9  * ---------------------------------------------------------------------------*/
10
11 #ifndef STGLDVPROF_H
12 #define STGLDVPROF_H
13
14 /*
15   An LDV word is divided into 3 parts: state bits (LDV_STATE_MASK), creation 
16   time bits (LDV_CREATE_MASK), and last use time bits (LDV_LAST_MASK). 
17  */
18 #if SIZEOF_VOID_P == 8
19 #define LDV_SHIFT               30
20 #define LDV_STATE_MASK          0x1000000000000000
21 #define LDV_CREATE_MASK         0x0FFFFFFFC0000000
22 #define LDV_LAST_MASK           0x000000003FFFFFFF
23 #define LDV_STATE_CREATE        0x0000000000000000
24 #define LDV_STATE_USE           0x1000000000000000
25 #else
26 #define LDV_SHIFT               15
27 #define LDV_STATE_MASK          0x40000000 
28 #define LDV_CREATE_MASK         0x3FFF8000
29 #define LDV_LAST_MASK           0x00007FFF
30 #define LDV_STATE_CREATE        0x00000000
31 #define LDV_STATE_USE           0x40000000
32 #endif  // SIZEOF_VOID_P
33
34 #ifdef PROFILING
35
36 extern nat era;
37
38 // retrieves the LDV word from closure c
39 #define LDVW(c)                 (((StgClosure *)(c))->header.prof.hp.ldvw)
40
41 // Stores the creation time for closure c. 
42 // This macro is called at the very moment of closure creation.
43 //
44 // NOTE: this initializes LDVW(c) to zero, which ensures that there
45 // is no conflict between retainer profiling and LDV profiling,
46 // because retainer profiling also expects LDVW(c) to be initialised
47 // to zero.
48 #define LDV_recordCreate(c)   \
49   LDVW((c)) = (era << LDV_SHIFT) | LDV_STATE_CREATE
50
51 // Stores the last use time for closure c.
52 // This macro *must* be called whenever a closure is used, that is, it is 
53 // entered.
54 #define LDV_recordUse(c)                                \
55   {                                                     \
56     if (era > 0)                                        \
57       LDVW((c)) = (LDVW((c)) & LDV_CREATE_MASK) |       \
58                   era |                                 \
59                   LDV_STATE_USE;                        \
60   }
61
62 // Macros called when a closure is entered. 
63 // The closure is not an 'inherently used' one.
64 // The closure is not IND or IND_OLDGEN because neither is considered for LDV
65 // profiling.
66 #define LDV_ENTER(c)            LDV_recordUse((c))
67
68 #else  // !PROFILING
69
70 #define LDV_ENTER(c)            
71
72 #endif // PROFILING
73 #endif // STGLDVPROF_H