1 Only have cost centres etc if @PROFILING@ defined
4 #define NULL_REG_MAP /* Not threaded */
5 #include "../storage/SMinternal.h" /* for ??? */
6 #if defined (PROFILING)
9 %************************************************************************
11 \subsection[indexing]{Indexing Cost Centres and Closure Categories}
13 %************************************************************************
15 See \tr{CostCentre.lh} for an overview.
19 CostCentre *index_cc_table = 0;
20 hash_t max_cc_no = DEFAULT_MAX_CC;
22 static hash_t index_cc_no = 0;
23 static hash_t mask_cc;
28 hash_t max2 = 1, count;
31 if (max_cc_no != mask_cc + 1) {
32 fprintf(stderr, "init_index_cc: twice %ld %ld\n", max_cc_no, mask_cc + 1);
38 while (max2 < max_cc_no) max2 <<= 1;
43 index_cc_table = (CostCentre *) stgMallocBytes(max2 * sizeof(CostCentre), "init_index_cc");
45 for (count = 0; count < max2; count++)
46 index_cc_table[count] = 0;
54 if (cc->index_val == UNHASHED) {
56 hash_t h = hash_fixed((char *)&cc, sizeof(CostCentre)) & mask_cc;
57 while (index_cc_table[h])
58 h = (h + 1) & mask_cc;
61 index_cc_table[h] = cc;
63 if (++index_cc_no > mask_cc - (mask_cc >> 6)) {
64 fprintf(stderr, "Cost Centre hash table full: %ld entries (in %ld table)\n",
65 index_cc_no, mask_cc+1);
66 fprintf(stderr, " +RTS -z%c<size> option will increase the hash table size\n", CCchar);
76 CostCentre *index_mod_table = 0;
77 hash_t max_mod_no = DEFAULT_MAX_MOD;
79 static hash_t index_mod_no = 0;
80 static hash_t mask_mod;
85 hash_t max2 = 1, count;
87 if (index_mod_table) {
88 if (max_mod_no != mask_mod + 1) {
89 fprintf(stderr, "init_index_mod: twice %ld %ld\n", max_mod_no, mask_mod + 1);
95 while (max2 < max_mod_no) max2 <<= 1;
100 index_mod_table = (CostCentre *) stgMallocBytes(max2 * sizeof(CostCentre), "init_index_mod");
102 for (count = 0; count < max2; count++)
103 index_mod_table[count] = 0;
112 if (cc->index_val == UNHASHED) {
114 hash_t h = hash_str(cc->module) & mask_mod;
116 while (index_mod_table[h] && (strcmp(index_mod_table[h]->module, cc->module) != 0))
117 h = (h + 1) & mask_mod;
120 index_mod_table[h] = cc; /* may replace existing cc at h index */
122 if (++index_mod_no > mask_mod - (mask_mod >> 6)) {
123 fprintf(stderr, "Module hash table full: %ld entries (in %ld table)\n",
124 index_mod_no, mask_mod+1);
125 fprintf(stderr, " +RTS -z%c<size> option will increase the hash table size\n", MODchar);
129 return cc->index_val;
136 CostCentre *index_grp_table = 0;
137 hash_t max_grp_no = DEFAULT_MAX_GRP;
139 static hash_t index_grp_no = 0;
140 static hash_t mask_grp;
145 hash_t max2 = 1, count;
147 if (index_grp_table) {
148 if (max_grp_no != mask_grp + 1) {
149 fprintf(stderr, "init_index_grp: twice %ld %ld\n", max_grp_no, mask_grp + 1);
155 while (max2 < max_grp_no) max2 <<= 1;
160 index_grp_table = (CostCentre *) stgMallocBytes(max2 * sizeof(CostCentre), "init_index_grp");
162 for (count = 0; count < max2; count++)
163 index_grp_table[count] = 0;
172 if (cc->index_val == UNHASHED) {
174 hash_t h = hash_str(cc->group) & mask_grp;
176 while (index_grp_table[h] && (strcmp(index_grp_table[h]->group, cc->group) != 0))
177 h = (h + 1) & mask_grp;
180 index_grp_table[h] = cc; /* may replace existing cc at h index */
182 if (++index_grp_no > mask_grp - (mask_grp >> 6)) {
183 fprintf(stderr, "Group hash table full: %ld entries (in %ld table)\n",
184 index_grp_no, mask_grp+1);
185 fprintf(stderr, " +RTS -z%c<size> option will increase the hash table size\n", GRPchar);
189 return cc->index_val;
196 ClCategory *index_descr_table = 0;
197 hash_t max_descr_no = DEFAULT_MAX_DESCR;
199 static hash_t index_descr_no = 0;
200 static hash_t mask_descr;
205 hash_t max2 = 1, count;
207 if (index_descr_table) {
208 if (max_descr_no != mask_descr + 1) {
209 fprintf(stderr, "init_index_descr: twice %ld %ld\n", max_descr_no, mask_descr + 1);
212 return mask_descr + 1;
215 while (max2 < max_descr_no) max2 <<= 1;
218 mask_descr = max2 - 1;
220 index_descr_table = (ClCategory *) stgMallocBytes(max2 * sizeof(ClCategory), "init_index_descr");
222 for (count = 0; count < max2; count++)
223 index_descr_table[count] = 0;
232 if (clcat->index_val == UNHASHED) {
234 hash_t h = hash_str(clcat->descr) & mask_descr;
236 while (index_descr_table[h] && (strcmp(index_descr_table[h]->descr, clcat->descr) != 0))
237 h = (h + 1) & mask_descr;
239 clcat->index_val = h;
240 index_descr_table[h] = clcat; /* may replace existing clcat at h index */
242 if (++index_descr_no > mask_descr - (mask_descr >> 6)) {
243 fprintf(stderr, "Closure Description hash table full: %ld entries (in %ld table)\n",
244 index_descr_no, mask_descr+1);
245 fprintf(stderr, " +RTS -z%c<size> option will increase the hash table size\n", DESCRchar);
249 return clcat->index_val;
256 ClCategory *index_type_table = 0;
257 hash_t max_type_no = DEFAULT_MAX_TYPE;
259 static hash_t index_type_no = 0;
260 static hash_t mask_type;
265 hash_t max2 = 1, count;
267 if (index_type_table) {
268 if (max_type_no != mask_type + 1) {
269 fprintf(stderr, "init_index_type: twice %ld %ld\n", max_type_no, mask_type + 1);
272 return mask_type + 1;
275 while (max2 < max_type_no) max2 <<= 1;
278 mask_type = max2 - 1;
280 index_type_table = (ClCategory *) stgMallocBytes(max2 * sizeof(ClCategory), "init_index_type");
282 for (count = 0; count < max2; count++)
283 index_type_table[count] = 0;
288 hash_t index_type(clcat)
291 if (clcat->index_val == UNHASHED) {
293 hash_t h = hash_str(clcat->type) & mask_type;
295 while (index_type_table[h] && (strcmp(index_type_table[h]->type, clcat->type) != 0))
296 h = (h + 1) & mask_type;
298 clcat->index_val = h;
299 index_type_table[h] = clcat; /* may replace existing clcat at h index */
301 if (++index_type_no > mask_type - (mask_type >> 6)) {
302 fprintf(stderr, "Type Description hash table full: %ld entries (in %ld table)\n",
303 index_type_no, mask_type+1);
304 fprintf(stderr, " +RTS -z%c<size> option will increase the hash table size\n", TYPEchar);
308 return clcat->index_val;
313 #endif /* PROFILING */