Home | History | Annotate | Download | only in callgrind

Lines Matching defs:bbcc

3 /*---                                                       bbcc.c ---*/
35 /*--- BBCC operations ---*/
40 /* BBCC table (key is BB/Context), per thread, resizable */
51 bbccs->table = (BBCC**) CLG_MALLOC("cl.bbcc.ibh.1",
52 bbccs->size * sizeof(BBCC*));
81 * Zero all costs of a BBCC
83 void CLG_(zero_bbcc)(BBCC* bbcc)
88 CLG_ASSERT(bbcc->cxt != 0);
91 bb_addr(bbcc->bb),
92 bbcc->cxt->base_number + bbcc->rec_index,
93 bbcc->cxt->fn[0]->name,
94 bbcc->rec_index);
96 if ((bbcc->ecounter_sum ==0) &&
97 (bbcc->ret_counter ==0)) return;
99 for(i=0;i<bbcc->bb->cost_count;i++)
100 bbcc->cost[i] = 0;
101 for(i=0;i <= bbcc->bb->cjmp_count;i++) {
102 bbcc->jmp[i].ecounter = 0;
103 for(jcc=bbcc->jmp[i].jcc_list; jcc; jcc=jcc->next_from)
106 bbcc->ecounter_sum = 0;
107 bbcc->ret_counter = 0;
112 void CLG_(forall_bbccs)(void (*func)(BBCC*))
114 BBCC *bbcc, *bbcc2;
118 if ((bbcc=current_bbccs.table[i]) == NULL) continue;
119 while (bbcc) {
120 /* every bbcc should have a rec_array */
121 CLG_ASSERT(bbcc->rec_array != 0);
123 for(j=0;j<bbcc->cxt->fn[0]->separate_recursions;j++) {
124 if ((bbcc2 = bbcc->rec_array[j]) == 0) continue;
128 bbcc = bbcc->next;
138 * BBCCs for other recursion levels are in bbcc->rec_array.
154 /* Lookup for a BBCC in hash.
157 BBCC* lookup_bbcc(BB* bb, Context* cxt)
159 BBCC* bbcc = bb->last_bbcc;
163 if (bbcc->cxt == cxt) {
166 return bbcc;
168 if (bbcc->tid == CLG_(current_tid)) return bbcc;
174 bbcc = current_bbccs.table[idx];
175 while (bbcc &&
176 (bb != bbcc->bb ||
177 cxt != bbcc->cxt)) {
178 bbcc = bbcc->next;
183 bbcc, bbcc ? bbcc->tid : 0);
186 if (bbcc) CLG_(print_bbcc)(-2,bbcc);
188 return bbcc;
192 /* double size of hash table 1 (addr->BBCC) */
196 BBCC** new_table;
198 BBCC *curr_BBCC, *next_BBCC;
201 new_table = (BBCC**) CLG_MALLOC("cl.bbcc.rbh.1",
202 new_size * sizeof(BBCC*));
235 CLG_DEBUG(0,"Resize BBCC Hash: %d => %d (entries %d, conflicts %d/%d)\n",
246 BBCC** new_recursion(int size)
248 BBCC** bbccs;
251 bbccs = (BBCC**) CLG_MALLOC("cl.bbcc.nr.1", sizeof(BBCC*) * size);
262 * Allocate a new BBCC
268 BBCC* new_bbcc(BB* bb)
270 BBCC* bbcc;
276 bbcc = (BBCC*)CLG_MALLOC("cl.bbcc.nb.1",
277 sizeof(BBCC) +
279 bbcc->bb = bb;
280 bbcc->tid = CLG_(current_tid);
282 bbcc->ret_counter = 0;
283 bbcc->skipped = 0;
284 bbcc->cost = CLG_(get_costarray)(bb->cost_count);
286 bbcc->cost[i] = 0;
288 bbcc->jmp[i].ecounter = 0;
289 bbcc->jmp[i].jcc_list = 0;
291 bbcc->ecounter_sum = 0;
294 bbcc->lru_next_bbcc = 0;
295 bbcc->lru_from_jcc = 0;
296 bbcc->lru_to_jcc = 0;
301 bb_addr(bb), bbcc, CLG_(stat).distinct_bbccs);
303 return bbcc;
308 * Inserts a new BBCC into hashes.
309 * BBCC specific items must be set as this is used for the hash
319 void insert_bbcc_into_hash(BBCC* bbcc)
323 CLG_ASSERT(bbcc->cxt != 0);
326 bb_addr(bbcc->bb), bbcc->cxt->fn[0]->name);
333 idx = bbcc_hash_idx(bbcc->bb, bbcc->cxt, current_bbccs.size);
334 bbcc->next = current_bbccs.table[idx];
335 current_bbccs.table[idx] = bbcc;
358 /* Create a new BBCC as a copy of an existing one,
365 * rec_index == 0: clone from a BBCC with differing tid/cxt
367 * rec_index >0 : clone from a BBCC with same tid/cxt and rec_index 0
370 static BBCC* clone_bbcc(BBCC* orig, Context* cxt, Int rec_index)
372 BBCC* bbcc;
377 bbcc = new_bbcc(orig->bb);
385 bbcc->rec_index = 0;
386 bbcc->cxt = cxt;
387 bbcc->rec_array = new_recursion(cxt->fn[0]->separate_recursions);
388 bbcc->rec_array[0] = bbcc;
390 insert_bbcc_into_hash(bbcc);
401 /* new BBCC will only have differing recursion level */
402 bbcc->rec_index = rec_index;
403 bbcc->cxt = cxt;
404 bbcc->rec_array = orig->rec_array;
405 bbcc->rec_array[rec_index] = bbcc;
409 bbcc->next_bbcc = orig->bb->bbcc_list;
410 orig->bb->bbcc_list = bbcc;
414 CLG_(print_bbcc)(-2, bbcc);
421 mangled_cxt(bbcc->cxt, bbcc->rec_index));
425 return bbcc;
431 * address. If created, the BBCC is inserted into the BBCC hash.
435 BBCC* CLG_(get_bbcc)(BB* bb)
437 BBCC* bbcc;
441 bbcc = bb->bbcc_list;
443 if (!bbcc) {
444 bbcc = new_bbcc(bb);
446 /* initialize BBCC */
447 bbcc->cxt = 0;
448 bbcc->rec_array = 0;
449 bbcc->rec_index = 0;
451 bbcc->next_bbcc = bb->bbcc_list;
452 bb->bbcc_list = bbcc;
453 bb->last_bbcc = bbcc;
456 CLG_(print_bbcc)(-2, bbcc);
459 CLG_DEBUG(3, "- get_bbcc(BB %#lx): BBCC %p\n",
460 bb_addr(bb), bbcc);
462 return bbcc;
481 BBCC* source_bbcc;
509 /* set rec array for source BBCC: this is at rec level 1 */
517 CLG_ASSERT(CLG_(current_state).bbcc);
520 fn_number = CLG_(current_state).bbcc->cxt->fn[0]->number;
530 CLG_(push_cxt)( CLG_(current_state).bbcc->cxt->fn[0] );
531 CLG_(push_call_stack)(source_bbcc, 0, CLG_(current_state).bbcc,
553 BBCC *bbcc, *last_bbcc;
580 last_bbcc = CLG_(current_state).bbcc;
689 CLG_(current_state).bbcc = top_ce->jcc->from;
722 /* Handle CALL/RET and update context to get correct BBCC */
764 /* If there is a fresh instrumented BBCC, assign current context */
765 bbcc = CLG_(get_bbcc)(bb);
766 if (bbcc->cxt == 0) {
767 CLG_ASSERT(bbcc->rec_array == 0);
769 bbcc->cxt = CLG_(current_state).cxt;
770 bbcc->rec_array =
772 bbcc->rec_array[0] = bbcc;
774 insert_bbcc_into_hash(bbcc);
777 /* get BBCC with current context */
779 /* first check LRU of last bbcc executed */
782 bbcc = last_bbcc->lru_next_bbcc;
783 if (bbcc &&
784 ((bbcc->bb != bb) ||
785 (bbcc->cxt != CLG_(current_state).cxt)))
786 bbcc = 0;
789 bbcc = 0;
791 if (!bbcc)
792 bbcc = lookup_bbcc(bb, CLG_(current_state).cxt);
793 if (!bbcc)
794 bbcc = clone_bbcc(bb->bbcc_list, CLG_(current_state).cxt, 0);
796 bb->last_bbcc = bbcc;
801 last_bbcc->lru_next_bbcc = bbcc;
812 CLG_ASSERT(CLG_(current_state).bbcc != 0);
814 if (CLG_(current_state).bbcc->cxt->fn[0] != bbcc->cxt->fn[0])
829 if (bbcc->rec_array[idx])
830 bbcc = bbcc->rec_array[idx];
832 bbcc = clone_bbcc(bbcc, CLG_(current_state).cxt, idx);
834 CLG_ASSERT(bbcc->rec_array[bbcc->rec_index] == bbcc);
840 CLG_(current_state).bbcc = CLG_(current_state).nonskipped;
842 passed = CLG_(current_state).bbcc->bb->cjmp_count;
844 CLG_(push_call_stack)(CLG_(current_state).bbcc, passed,
845 bbcc, sp, skip);
853 jCC* jcc = CLG_(get_jcc)(last_bbcc, passed, bbcc);
870 CLG_(current_state).bbcc = bbcc;
873 CLG_(cost_base) = bbcc->cost;
877 CLG_(print_bbcc_fn)(bbcc);
882 bb_addr(bb), bbcc->cost, bb->cost_count,
885 CLG_(print_cxt)(-8, CLG_(current_state).cxt, bbcc->rec_index);