Home | History | Annotate | Download | only in callgrind

Lines Matching refs: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*));
233 CLG_DEBUG(0,"Resize BBCC Hash: %d => %d (entries %d, conflicts %d/%d)\n",
244 BBCC** new_recursion(int size)
246 BBCC** bbccs;
249 bbccs = (BBCC**) CLG_MALLOC("cl.bbcc.nr.1", sizeof(BBCC*) * size);
260 * Allocate a new BBCC
266 BBCC* new_bbcc(BB* bb)
268 BBCC* bbcc;
274 bbcc = (BBCC*)CLG_MALLOC("cl.bbcc.nb.1",
275 sizeof(BBCC) +
277 bbcc->bb = bb;
278 bbcc->tid = CLG_(current_tid);
280 bbcc->ret_counter = 0;
281 bbcc->skipped = 0;
282 bbcc->cost = CLG_(get_costarray)(bb->cost_count);
284 bbcc->cost[i] = 0;
286 bbcc->jmp[i].ecounter = 0;
287 bbcc->jmp[i].jcc_list = 0;
289 bbcc->ecounter_sum = 0;
292 bbcc->lru_next_bbcc = 0;
293 bbcc->lru_from_jcc = 0;
294 bbcc->lru_to_jcc = 0;
299 bb_addr(bb), bbcc, CLG_(stat).distinct_bbccs);
301 return bbcc;
306 * Inserts a new BBCC into hashes.
307 * BBCC specific items must be set as this is used for the hash
317 void insert_bbcc_into_hash(BBCC* bbcc)
321 CLG_ASSERT(bbcc->cxt != 0);
324 bb_addr(bbcc->bb), bbcc->cxt->fn[0]->name);
331 idx = bbcc_hash_idx(bbcc->bb, bbcc->cxt, current_bbccs.size);
332 bbcc->next = current_bbccs.table[idx];
333 current_bbccs.table[idx] = bbcc;
345 if (!cxt) return VG_(strdup)("cl.bbcc.mcxt", "(no context)");
352 HChar *mangled = CLG_MALLOC("cl.bbcc.mcxt", need);
363 /* Create a new BBCC as a copy of an existing one,
370 * rec_index == 0: clone from a BBCC with differing tid/cxt
372 * rec_index >0 : clone from a BBCC with same tid/cxt and rec_index 0
375 static BBCC* clone_bbcc(BBCC* orig, Context* cxt, Int rec_index)
377 BBCC* bbcc;
382 bbcc = new_bbcc(orig->bb);
390 bbcc->rec_index = 0;
391 bbcc->cxt = cxt;
392 bbcc->rec_array = new_recursion(cxt->fn[0]->separate_recursions);
393 bbcc->rec_array[0] = bbcc;
395 insert_bbcc_into_hash(bbcc);
406 /* new BBCC will only have differing recursion level */
407 bbcc->rec_index = rec_index;
408 bbcc->cxt = cxt;
409 bbcc->rec_array = orig->rec_array;
410 bbcc->rec_array[rec_index] = bbcc;
414 bbcc->next_bbcc = orig->bb->bbcc_list;
415 orig->bb->bbcc_list = bbcc;
419 CLG_(print_bbcc)(-2, bbcc);
422 HChar *mangled_bbcc = mangled_cxt(bbcc->cxt, bbcc->rec_index);
434 return bbcc;
440 * address. If created, the BBCC is inserted into the BBCC hash.
444 BBCC* CLG_(get_bbcc)(BB* bb)
446 BBCC* bbcc;
450 bbcc = bb->bbcc_list;
452 if (!bbcc) {
453 bbcc = new_bbcc(bb);
455 /* initialize BBCC */
456 bbcc->cxt = 0;
457 bbcc->rec_array = 0;
458 bbcc->rec_index = 0;
460 bbcc->next_bbcc = bb->bbcc_list;
461 bb->bbcc_list = bbcc;
462 bb->last_bbcc = bbcc;
465 CLG_(print_bbcc)(-2, bbcc);
468 CLG_DEBUG(3, "- get_bbcc(BB %#lx): BBCC %p\n",
469 bb_addr(bb), bbcc);
471 return bbcc;
490 BBCC* source_bbcc;
519 /* set rec array for source BBCC: this is at rec level 1 */
527 CLG_ASSERT(CLG_(current_state).bbcc);
530 fn_number = CLG_(current_state).bbcc->cxt->fn[0]->number;
540 CLG_(push_cxt)( CLG_(current_state).bbcc->cxt->fn[0] );
541 CLG_(push_call_stack)(source_bbcc, 0, CLG_(current_state).bbcc,
563 BBCC *bbcc, *last_bbcc;
595 last_bbcc = CLG_(current_state).bbcc;
713 CLG_(current_state).bbcc = top_ce->jcc->from;
746 /* Handle CALL/RET and update context to get correct BBCC */
788 /* If there is a fresh instrumented BBCC, assign current context */
789 bbcc = CLG_(get_bbcc)(bb);
790 if (bbcc->cxt == 0) {
791 CLG_ASSERT(bbcc->rec_array == 0);
793 bbcc->cxt = CLG_(current_state).cxt;
794 bbcc->rec_array =
796 bbcc->rec_array[0] = bbcc;
798 insert_bbcc_into_hash(bbcc);
801 /* get BBCC with current context */
803 /* first check LRU of last bbcc executed */
806 bbcc = last_bbcc->lru_next_bbcc;
807 if (bbcc &&
808 ((bbcc->bb != bb) ||
809 (bbcc->cxt != CLG_(current_state).cxt)))
810 bbcc = 0;
813 bbcc = 0;
815 if (!bbcc)
816 bbcc = lookup_bbcc(bb, CLG_(current_state).cxt);
817 if (!bbcc)
818 bbcc = clone_bbcc(bb->bbcc_list, CLG_(current_state).cxt, 0);
820 bb->last_bbcc = bbcc;
825 last_bbcc->lru_next_bbcc = bbcc;
836 CLG_ASSERT(CLG_(current_state).bbcc != 0);
838 if (CLG_(current_state).bbcc->cxt->fn[0] != bbcc->cxt->fn[0])
853 if (bbcc->rec_array[idx])
854 bbcc = bbcc->rec_array[idx];
856 bbcc = clone_bbcc(bbcc, CLG_(current_state).cxt, idx);
858 CLG_ASSERT(bbcc->rec_array[bbcc->rec_index] == bbcc);
864 CLG_(current_state).bbcc = CLG_(current_state).nonskipped;
866 passed = CLG_(current_state).bbcc->bb->cjmp_count;
868 CLG_(push_call_stack)(CLG_(current_state).bbcc, passed,
869 bbcc, sp, skip);
877 jCC* jcc = CLG_(get_jcc)(last_bbcc, passed, bbcc);
894 CLG_(current_state).bbcc = bbcc;
901 CLG_(cost_base) = bbcc->cost;
905 CLG_(print_bbcc_fn)(bbcc);
910 bb_addr(bb), bbcc->cost, bb->cost_count,
913 CLG_(print_cxt)(-8, CLG_(current_state).cxt, bbcc->rec_index);