1 Only have cost centres etc if @USE_COST_CENTRES@ defined
4 #define NULL_REG_MAP /* Not threaded */
5 #include "../storage/SMinternal.h" /* for xmalloc */
6 #if defined (USE_COST_CENTRES)
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 *) xmalloc(max2 * sizeof(CostCentre));
44 for (count = 0; count < max2; count++) index_cc_table[count] = 0;
52 if (cc->index_val == UNHASHED) {
54 hash_t h = hash_fixed((char *)&cc, sizeof(CostCentre)) & mask_cc;
55 while (index_cc_table[h])
56 h = (h + 1) & mask_cc;
59 index_cc_table[h] = cc;
61 if (++index_cc_no > mask_cc - (mask_cc >> 6)) {
62 fprintf(stderr, "Cost Centre hash table full: %ld entries (in %ld table)\n",
63 index_cc_no, mask_cc+1);
64 fprintf(stderr, " +RTS -z%c<size> option will increase the hash table size\n", CCchar);
74 CostCentre *index_mod_table = 0;
75 hash_t max_mod_no = DEFAULT_MAX_MOD;
77 static hash_t index_mod_no = 0;
78 static hash_t mask_mod;
83 hash_t max2 = 1, count;
85 if (index_mod_table) {
86 if (max_mod_no != mask_mod + 1) {
87 fprintf(stderr, "init_index_mod: twice %ld %ld\n", max_mod_no, mask_mod + 1);
93 while (max2 < max_mod_no) max2 <<= 1;
98 index_mod_table = (CostCentre *) xmalloc(max2 * sizeof(CostCentre));
99 for (count = 0; count < max2; count++) index_mod_table[count] = 0;
107 if (cc->index_val == UNHASHED) {
109 hash_t h = hash_str(cc->module) & mask_mod;
111 while (index_mod_table[h] && (strcmp(index_mod_table[h]->module, cc->module) != 0))
112 h = (h + 1) & mask_mod;
115 index_mod_table[h] = cc; /* may replace existing cc at h index */
117 if (++index_mod_no > mask_mod - (mask_mod >> 6)) {
118 fprintf(stderr, "Module hash table full: %ld entries (in %ld table)\n",
119 index_mod_no, mask_mod+1);
120 fprintf(stderr, " +RTS -z%c<size> option will increase the hash table size\n", MODchar);
124 return cc->index_val;
131 CostCentre *index_grp_table = 0;
132 hash_t max_grp_no = DEFAULT_MAX_GRP;
134 static hash_t index_grp_no = 0;
135 static hash_t mask_grp;
140 hash_t max2 = 1, count;
142 if (index_grp_table) {
143 if (max_grp_no != mask_grp + 1) {
144 fprintf(stderr, "init_index_grp: twice %ld %ld\n", max_grp_no, mask_grp + 1);
150 while (max2 < max_grp_no) max2 <<= 1;
155 index_grp_table = (CostCentre *) xmalloc(max2 * sizeof(CostCentre));
156 for (count = 0; count < max2; count++) index_grp_table[count] = 0;
164 if (cc->index_val == UNHASHED) {
166 hash_t h = hash_str(cc->group) & mask_grp;
168 while (index_grp_table[h] && (strcmp(index_grp_table[h]->group, cc->group) != 0))
169 h = (h + 1) & mask_grp;
172 index_grp_table[h] = cc; /* may replace existing cc at h index */
174 if (++index_grp_no > mask_grp - (mask_grp >> 6)) {
175 fprintf(stderr, "Group hash table full: %ld entries (in %ld table)\n",
176 index_grp_no, mask_grp+1);
177 fprintf(stderr, " +RTS -z%c<size> option will increase the hash table size\n", GRPchar);
181 return cc->index_val;
188 ClCategory *index_descr_table = 0;
189 hash_t max_descr_no = DEFAULT_MAX_DESCR;
191 static hash_t index_descr_no = 0;
192 static hash_t mask_descr;
197 hash_t max2 = 1, count;
199 if (index_descr_table) {
200 if (max_descr_no != mask_descr + 1) {
201 fprintf(stderr, "init_index_descr: twice %ld %ld\n", max_descr_no, mask_descr + 1);
204 return mask_descr + 1;
207 while (max2 < max_descr_no) max2 <<= 1;
210 mask_descr = max2 - 1;
212 index_descr_table = (ClCategory *) xmalloc(max2 * sizeof(ClCategory));
213 for (count = 0; count < max2; count++) index_descr_table[count] = 0;
218 hash_t index_descr(clcat)
221 if (clcat->index_val == UNHASHED) {
223 hash_t h = hash_str(clcat->descr) & mask_descr;
225 while (index_descr_table[h] && (strcmp(index_descr_table[h]->descr, clcat->descr) != 0))
226 h = (h + 1) & mask_descr;
228 clcat->index_val = h;
229 index_descr_table[h] = clcat; /* may replace existing clcat at h index */
231 if (++index_descr_no > mask_descr - (mask_descr >> 6)) {
232 fprintf(stderr, "Closure Description hash table full: %ld entries (in %ld table)\n",
233 index_descr_no, mask_descr+1);
234 fprintf(stderr, " +RTS -z%c<size> option will increase the hash table size\n", DESCRchar);
238 return clcat->index_val;
245 ClCategory *index_type_table = 0;
246 hash_t max_type_no = DEFAULT_MAX_TYPE;
248 static hash_t index_type_no = 0;
249 static hash_t mask_type;
254 hash_t max2 = 1, count;
256 if (index_type_table) {
257 if (max_type_no != mask_type + 1) {
258 fprintf(stderr, "init_index_type: twice %ld %ld\n", max_type_no, mask_type + 1);
261 return mask_type + 1;
264 while (max2 < max_type_no) max2 <<= 1;
267 mask_type = max2 - 1;
269 index_type_table = (ClCategory *) xmalloc(max2 * sizeof(ClCategory));
270 for (count = 0; count < max2; count++) index_type_table[count] = 0;
275 hash_t index_type(clcat)
278 if (clcat->index_val == UNHASHED) {
280 hash_t h = hash_str(clcat->type) & mask_type;
282 while (index_type_table[h] && (strcmp(index_type_table[h]->type, clcat->type) != 0))
283 h = (h + 1) & mask_type;
285 clcat->index_val = h;
286 index_type_table[h] = clcat; /* may replace existing clcat at h index */
288 if (++index_type_no > mask_type - (mask_type >> 6)) {
289 fprintf(stderr, "Type Description hash table full: %ld entries (in %ld table)\n",
290 index_type_no, mask_type+1);
291 fprintf(stderr, " +RTS -z%c<size> option will increase the hash table size\n", TYPEchar);
295 return clcat->index_val;
300 #endif /* USE_COST_CENTRES */