6 #include "concretepredicate.h"
10 #include "newfuzzer.h"
13 FuncNode::FuncNode(ModelHistory * history) :
18 thrd_recursion_depth(),
22 thrd_inst_pred_maps(),
25 thrd_predicate_tree_position(),
26 thrd_predicate_trace(),
30 predicate_tree_entry = new Predicate(NULL, true);
31 predicate_tree_entry->add_predicate_expr(NOPREDICATE, NULL, true);
33 predicate_tree_exit = new Predicate(NULL, false, true);
34 predicate_tree_exit->set_depth(MAX_DEPTH);
36 /* Snapshot data structures below */
37 read_locations = new loc_set_t();
38 write_locations = new loc_set_t();
39 val_loc_map = new HashTable<uint64_t, loc_set_t *, uint64_t, 0, snapshot_malloc, snapshot_calloc, snapshot_free, int64_hash>();
40 loc_may_equal_map = new HashTable<void *, loc_set_t *, uintptr_t, 0>();
42 //values_may_read_from = new value_set_t();
45 /* Reallocate snapshotted memories when new executions start */
46 void FuncNode::set_new_exec_flag()
48 read_locations = new loc_set_t();
49 write_locations = new loc_set_t();
50 val_loc_map = new HashTable<uint64_t, loc_set_t *, uint64_t, 0, snapshot_malloc, snapshot_calloc, snapshot_free, int64_hash>();
51 loc_may_equal_map = new HashTable<void *, loc_set_t *, uintptr_t, 0>();
53 //values_may_read_from = new value_set_t();
56 /* Check whether FuncInst with the same type, position, and location
57 * as act has been added to func_inst_map or not. If not, add it.
59 void FuncNode::add_inst(ModelAction *act)
62 const char * position = act->get_position();
64 /* THREAD* actions, ATOMIC_LOCK, ATOMIC_TRYLOCK, and ATOMIC_UNLOCK
65 * actions are not tagged with their source line numbers
70 FuncInst * func_inst = func_inst_map.get(position);
72 /* This position has not been inserted into hashtable before */
73 if (func_inst == NULL) {
74 func_inst = create_new_inst(act);
75 func_inst_map.put(position, func_inst);
79 /* Volatile variables that use ++ or -- syntax may result in read and write actions with the same position */
80 if (func_inst->get_type() != act->get_type()) {
81 FuncInst * collision_inst = func_inst->search_in_collision(act);
83 if (collision_inst == NULL) {
84 collision_inst = create_new_inst(act);
85 func_inst->add_to_collision(collision_inst);
88 func_inst = collision_inst;
92 ASSERT(func_inst->get_type() == act->get_type());
93 int curr_execution_number = model->get_execution_number();
95 /* Reset locations when new executions start */
96 if (func_inst->get_execution_number() != curr_execution_number) {
97 func_inst->set_location(act->get_location());
98 func_inst->set_execution_number(curr_execution_number);
101 /* Mark the memory location of such inst as not unique */
102 if (func_inst->get_location() != act->get_location())
103 func_inst->not_single_location();
106 FuncInst * FuncNode::create_new_inst(ModelAction * act)
108 FuncInst * func_inst = new FuncInst(act, this);
109 int exec_num = model->get_execution_number();
110 func_inst->set_execution_number(exec_num);
112 inst_list.push_back(func_inst);
118 /* Get the FuncInst with the same type, position, and location
121 * @return FuncInst with the same type, position, and location as act */
122 FuncInst * FuncNode::get_inst(ModelAction *act)
125 const char * position = act->get_position();
127 /* THREAD* actions, ATOMIC_LOCK, ATOMIC_TRYLOCK, and ATOMIC_UNLOCK
128 * actions are not tagged with their source line numbers
130 if (position == NULL)
133 FuncInst * inst = func_inst_map.get(position);
137 action_type inst_type = inst->get_type();
138 action_type act_type = act->get_type();
140 if (inst_type == act_type) {
143 /* RMWRCAS actions are converted to RMW or READ actions */
144 else if (inst_type == ATOMIC_RMWRCAS &&
145 (act_type == ATOMIC_RMW || act_type == ATOMIC_READ)) {
148 /* Return the FuncInst in the collision list */
150 return inst->search_in_collision(act);
154 void FuncNode::add_entry_inst(FuncInst * inst)
159 mllnode<FuncInst *> * it;
160 for (it = entry_insts.begin();it != NULL;it = it->getNext()) {
161 if (inst == it->getVal())
165 entry_insts.push_back(inst);
168 void FuncNode::function_entry_handler(thread_id_t tid)
171 init_local_maps(tid);
172 init_predicate_tree_data_structure(tid);
175 void FuncNode::function_exit_handler(thread_id_t tid)
177 int thread_id = id_to_int(tid);
179 reset_local_maps(tid);
181 thrd_recursion_depth[thread_id]--;
182 thrd_markers[thread_id]->pop_back();
184 Predicate * exit_pred = get_predicate_tree_position(tid);
185 if (exit_pred->get_exit() == NULL) {
186 // Exit predicate is unset yet
187 exit_pred->set_exit(predicate_tree_exit);
190 update_predicate_tree_weight(tid);
191 reset_predicate_tree_data_structure(tid);
195 * @brief Convert ModelAdtion list to FuncInst list
196 * @param act_list A list of ModelActions
198 void FuncNode::update_tree(ModelAction * act)
200 bool should_process = act->is_read() || act->is_write();
204 HashTable<void *, value_set_t *, uintptr_t, 0> * write_history = history->getWriteHistory();
206 /* build inst_list from act_list for later processing */
207 // func_inst_list_t inst_list;
209 FuncInst * func_inst = get_inst(act);
210 void * loc = act->get_location();
212 if (func_inst == NULL)
215 // inst_list.push_back(func_inst);
217 if (act->is_write()) {
218 if (!write_locations->contains(loc)) {
219 write_locations->add(loc);
220 history->update_loc_wr_func_nodes_map(loc, this);
223 // Do not process writes for now
227 if (act->is_read()) {
229 /* If func_inst may only read_from a single location, then:
231 * The first time an action reads from some location,
232 * import all the values that have been written to this
233 * location from ModelHistory and notify ModelHistory
234 * that this FuncNode may read from this location.
236 if (!read_locations->contains(loc) && func_inst->is_single_location()) {
237 read_locations->add(loc);
238 value_set_t * write_values = write_history->get(loc);
239 add_to_val_loc_map(write_values, loc);
240 history->update_loc_rd_func_nodes_map(loc, this);
244 // update_inst_tree(&inst_list); TODO
245 update_predicate_tree(act);
247 // print_predicate_tree();
251 * @brief Link FuncInsts in inst_list - add one FuncInst to another's predecessors and successors
252 * @param inst_list A list of FuncInsts
254 void FuncNode::update_inst_tree(func_inst_list_t * inst_list)
256 if (inst_list == NULL)
258 else if (inst_list->size() == 0)
262 sllnode<FuncInst *>* it = inst_list->begin();
263 sllnode<FuncInst *>* prev;
265 /* add the first instruction to the list of entry insts */
266 FuncInst * entry_inst = it->getVal();
267 add_entry_inst(entry_inst);
271 prev = it->getPrev();
273 FuncInst * prev_inst = prev->getVal();
274 FuncInst * curr_inst = it->getVal();
276 prev_inst->add_succ(curr_inst);
277 curr_inst->add_pred(prev_inst);
283 void FuncNode::update_predicate_tree(ModelAction * next_act)
285 thread_id_t tid = next_act->get_tid();
286 int thread_id = id_to_int(tid);
287 uint32_t this_marker = thrd_markers[thread_id]->back();
288 int recursion_depth = thrd_recursion_depth[thread_id];
290 loc_inst_map_t * loc_inst_map = thrd_loc_inst_maps[thread_id]->back();
291 inst_pred_map_t * inst_pred_map = thrd_inst_pred_maps[thread_id]->back();
292 inst_id_map_t * inst_id_map = thrd_inst_id_maps[thread_id]->back();
294 Predicate * curr_pred = get_predicate_tree_position(tid);
295 NewFuzzer * fuzzer = (NewFuzzer *)model->get_execution()->getFuzzer();
296 Predicate * selected_branch = fuzzer->get_selected_child_branch(tid);
299 FuncInst * next_inst = get_inst(next_act);
300 next_inst->set_associated_read(tid, recursion_depth, this_marker, next_act->get_reads_from_value());
302 Predicate * unset_predicate = NULL;
303 bool branch_found = follow_branch(&curr_pred, next_inst, next_act, &unset_predicate);
305 // A branch with unset predicate expression is detected
306 if (!branch_found && unset_predicate != NULL) {
307 bool amended = amend_predicate_expr(curr_pred, next_inst, next_act);
311 curr_pred = unset_predicate;
317 if (!branch_found && inst_id_map->contains(next_inst)) {
318 FuncInst * curr_inst = curr_pred->get_func_inst();
319 uint32_t curr_id = inst_id_map->get(curr_inst);
320 uint32_t next_id = inst_id_map->get(next_inst);
322 if (curr_id >= next_id) {
323 Predicate * old_pred = inst_pred_map->get(next_inst);
324 Predicate * back_pred = old_pred->get_parent();
326 // Add to the set of backedges
327 curr_pred->add_backedge(back_pred);
328 curr_pred = back_pred;
334 // Generate new branches
336 SnapVector<struct half_pred_expr *> half_pred_expressions;
337 infer_predicates(next_inst, next_act, &half_pred_expressions);
338 generate_predicates(curr_pred, next_inst, &half_pred_expressions);
342 if (next_act->is_write())
343 curr_pred->set_write(true);
345 if (next_act->is_read()) {
346 /* Only need to store the locations of read actions */
347 loc_inst_map->put(next_inst->get_location(), next_inst);
350 inst_pred_map->put(next_inst, curr_pred);
351 set_predicate_tree_position(tid, curr_pred);
353 if (!inst_id_map->contains(next_inst))
354 inst_id_map->put(next_inst, inst_counter++);
356 curr_pred->incr_expl_count();
357 add_predicate_to_trace(tid, curr_pred);
362 if (selected_branch != NULL)
363 ASSERT(selected_branch == curr_pred);
366 /* Given curr_pred and next_inst, find the branch following curr_pred that
367 * contains next_inst and the correct predicate.
368 * @return true if branch found, false otherwise.
370 bool FuncNode::follow_branch(Predicate ** curr_pred, FuncInst * next_inst,
371 ModelAction * next_act, Predicate ** unset_predicate)
373 /* Check if a branch with func_inst and corresponding predicate exists */
374 bool branch_found = false;
375 thread_id_t tid = next_act->get_tid();
376 int thread_id = id_to_int(tid);
377 uint32_t this_marker = thrd_markers[thread_id]->back();
378 int recursion_depth = thrd_recursion_depth[thread_id];
380 ModelVector<Predicate *> * branches = (*curr_pred)->get_children();
381 for (uint i = 0;i < branches->size();i++) {
382 Predicate * branch = (*branches)[i];
383 if (branch->get_func_inst() != next_inst)
386 /* Check against predicate expressions */
387 bool predicate_correct = true;
388 PredExprSet * pred_expressions = branch->get_pred_expressions();
390 /* Only read and rmw actions my have unset predicate expressions */
391 if (pred_expressions->getSize() == 0) {
392 predicate_correct = false;
394 if (*unset_predicate == NULL)
395 *unset_predicate = branch;
402 PredExprSetIter * pred_expr_it = pred_expressions->iterator();
403 while (pred_expr_it->hasNext()) {
404 pred_expr * pred_expression = pred_expr_it->next();
405 uint64_t last_read, next_read;
408 switch(pred_expression->token) {
410 predicate_correct = true;
413 FuncInst * to_be_compared;
414 to_be_compared = pred_expression->func_inst;
415 ASSERT(to_be_compared != next_inst);
417 last_read = to_be_compared->get_associated_read(tid, recursion_depth, this_marker);
418 ASSERT(last_read != VALUE_NONE);
420 next_read = next_act->get_reads_from_value();
421 equality = (last_read == next_read);
422 if (equality != pred_expression->value)
423 predicate_correct = false;
427 next_read = next_act->get_reads_from_value();
428 // TODO: implement likely to be null
429 equality = ( (void*) (next_read & 0xffffffff) == NULL);
430 if (equality != pred_expression->value)
431 predicate_correct = false;
434 predicate_correct = false;
435 model_print("unkown predicate token\n");
442 if (predicate_correct) {
452 /* Infer predicate expressions, which are generated in FuncNode::generate_predicates */
453 void FuncNode::infer_predicates(FuncInst * next_inst, ModelAction * next_act,
454 SnapVector<struct half_pred_expr *> * half_pred_expressions)
456 void * loc = next_act->get_location();
457 int thread_id = id_to_int(next_act->get_tid());
458 loc_inst_map_t * loc_inst_map = thrd_loc_inst_maps[thread_id]->back();
460 if (next_inst->is_read()) {
462 if ( loc_inst_map->contains(loc) ) {
463 FuncInst * last_inst = loc_inst_map->get(loc);
464 struct half_pred_expr * expression = new half_pred_expr(EQUALITY, last_inst);
465 half_pred_expressions->push_back(expression);
466 } else if ( next_inst->is_single_location() ) {
467 loc_set_t * loc_may_equal = loc_may_equal_map->get(loc);
469 if (loc_may_equal != NULL) {
470 loc_set_iter * loc_it = loc_may_equal->iterator();
471 while (loc_it->hasNext()) {
472 void * neighbor = loc_it->next();
473 if (loc_inst_map->contains(neighbor)) {
474 FuncInst * last_inst = loc_inst_map->get(neighbor);
476 struct half_pred_expr * expression = new half_pred_expr(EQUALITY, last_inst);
477 half_pred_expressions->push_back(expression);
484 // next_inst is not single location
485 uint64_t read_val = next_act->get_reads_from_value();
487 // only infer NULLITY predicate when it is actually NULL.
488 if ( (void*)read_val == NULL) {
489 struct half_pred_expr * expression = new half_pred_expr(NULLITY, NULL);
490 half_pred_expressions->push_back(expression);
495 // TODO: do anything here?
499 /* Able to generate complex predicates when there are multiple predciate expressions */
500 void FuncNode::generate_predicates(Predicate * curr_pred, FuncInst * next_inst,
501 SnapVector<struct half_pred_expr *> * half_pred_expressions)
503 if (half_pred_expressions->size() == 0) {
504 Predicate * new_pred = new Predicate(next_inst);
505 curr_pred->add_child(new_pred);
506 new_pred->set_parent(curr_pred);
508 /* entry predicates and predicates containing pure write actions
509 * have no predicate expressions */
510 if ( curr_pred->is_entry_predicate() )
511 new_pred->add_predicate_expr(NOPREDICATE, NULL, true);
512 else if (next_inst->is_write()) {
513 /* next_inst->is_write() <==> pure writes */
514 new_pred->add_predicate_expr(NOPREDICATE, NULL, true);
520 SnapVector<Predicate *> predicates;
522 struct half_pred_expr * half_expr = (*half_pred_expressions)[0];
523 predicates.push_back(new Predicate(next_inst));
524 predicates.push_back(new Predicate(next_inst));
526 predicates[0]->add_predicate_expr(half_expr->token, half_expr->func_inst, true);
527 predicates[1]->add_predicate_expr(half_expr->token, half_expr->func_inst, false);
529 for (uint i = 1;i < half_pred_expressions->size();i++) {
530 half_expr = (*half_pred_expressions)[i];
532 uint old_size = predicates.size();
533 for (uint j = 0;j < old_size;j++) {
534 Predicate * pred = predicates[j];
535 Predicate * new_pred = new Predicate(next_inst);
536 new_pred->copy_predicate_expr(pred);
538 pred->add_predicate_expr(half_expr->token, half_expr->func_inst, true);
539 new_pred->add_predicate_expr(half_expr->token, half_expr->func_inst, false);
541 predicates.push_back(new_pred);
545 for (uint i = 0;i < predicates.size();i++) {
546 Predicate * pred= predicates[i];
547 curr_pred->add_child(pred);
548 pred->set_parent(curr_pred);
551 /* Free memories allocated by infer_predicate */
552 for (uint i = 0;i < half_pred_expressions->size();i++) {
553 struct half_pred_expr * tmp = (*half_pred_expressions)[i];
558 /* Amend predicates that contain no predicate expressions. Currenlty only amend with NULLITY predicates */
559 bool FuncNode::amend_predicate_expr(Predicate * curr_pred, FuncInst * next_inst, ModelAction * next_act)
561 ModelVector<Predicate *> * children = curr_pred->get_children();
563 Predicate * unset_pred = NULL;
564 for (uint i = 0;i < children->size();i++) {
565 Predicate * child = (*children)[i];
566 if (child->get_func_inst() == next_inst) {
572 uint64_t read_val = next_act->get_reads_from_value();
574 // only generate NULLITY predicate when it is actually NULL.
575 if ( !next_inst->is_single_location() && (void*)read_val == NULL ) {
576 Predicate * new_pred = new Predicate(next_inst);
578 curr_pred->add_child(new_pred);
579 new_pred->set_parent(curr_pred);
581 unset_pred->add_predicate_expr(NULLITY, NULL, false);
582 new_pred->add_predicate_expr(NULLITY, NULL, true);
590 void FuncNode::add_to_val_loc_map(uint64_t val, void * loc)
592 loc_set_t * locations = val_loc_map->get(val);
594 if (locations == NULL) {
595 locations = new loc_set_t();
596 val_loc_map->put(val, locations);
599 update_loc_may_equal_map(loc, locations);
601 // values_may_read_from->add(val);
604 void FuncNode::add_to_val_loc_map(value_set_t * values, void * loc)
609 value_set_iter * it = values->iterator();
610 while (it->hasNext()) {
611 uint64_t val = it->next();
612 add_to_val_loc_map(val, loc);
618 void FuncNode::update_loc_may_equal_map(void * new_loc, loc_set_t * old_locations)
620 if ( old_locations->contains(new_loc) )
623 loc_set_t * neighbors = loc_may_equal_map->get(new_loc);
625 if (neighbors == NULL) {
626 neighbors = new loc_set_t();
627 loc_may_equal_map->put(new_loc, neighbors);
630 loc_set_iter * loc_it = old_locations->iterator();
631 while (loc_it->hasNext()) {
632 // new_loc: { old_locations, ... }
633 void * member = loc_it->next();
634 neighbors->add(member);
636 // for each i in old_locations, i : { new_loc, ... }
637 loc_set_t * _neighbors = loc_may_equal_map->get(member);
638 if (_neighbors == NULL) {
639 _neighbors = new loc_set_t();
640 loc_may_equal_map->put(member, _neighbors);
642 _neighbors->add(new_loc);
648 void FuncNode::set_predicate_tree_position(thread_id_t tid, Predicate * pred)
650 int thread_id = id_to_int(tid);
651 ModelVector<Predicate *> * stack = thrd_predicate_tree_position[thread_id];
652 (*stack)[stack->size() - 1] = pred;
655 /* @return The position of a thread in a predicate tree */
656 Predicate * FuncNode::get_predicate_tree_position(thread_id_t tid)
658 int thread_id = id_to_int(tid);
659 return thrd_predicate_tree_position[thread_id]->back();
662 void FuncNode::add_predicate_to_trace(thread_id_t tid, Predicate * pred)
664 int thread_id = id_to_int(tid);
665 thrd_predicate_trace[thread_id]->back()->push_back(pred);
668 void FuncNode::init_marker(thread_id_t tid)
672 int thread_id = id_to_int(tid);
673 int old_size = thrd_markers.size();
675 if (old_size < thread_id + 1) {
676 thrd_markers.resize(thread_id + 1);
678 for (int i = old_size; i < thread_id + 1; i++) {
679 thrd_markers[i] = new ModelVector<uint32_t>();
680 thrd_recursion_depth.push_back(-1);
684 thrd_markers[thread_id]->push_back(marker);
685 thrd_recursion_depth[thread_id]++;
688 uint32_t FuncNode::get_marker(thread_id_t tid)
690 int thread_id = id_to_int(tid);
691 return thrd_markers[thread_id]->back();
694 int FuncNode::get_recursion_depth(thread_id_t tid)
696 return thrd_recursion_depth[id_to_int(tid)];
699 /* Make sure elements of maps are initialized properly when threads enter functions */
700 void FuncNode::init_local_maps(thread_id_t tid)
702 int thread_id = id_to_int(tid);
703 int old_size = thrd_loc_inst_maps.size();
705 if (old_size < thread_id + 1) {
706 int new_size = thread_id + 1;
708 thrd_loc_inst_maps.resize(new_size);
709 thrd_inst_id_maps.resize(new_size);
710 thrd_inst_pred_maps.resize(new_size);
712 for (int i = old_size; i < new_size; i++) {
713 thrd_loc_inst_maps[i] = new ModelVector<loc_inst_map_t *>;
714 thrd_inst_id_maps[i] = new ModelVector<inst_id_map_t *>;
715 thrd_inst_pred_maps[i] = new ModelVector<inst_pred_map_t *>;
719 ModelVector<loc_inst_map_t *> * map = thrd_loc_inst_maps[thread_id];
720 int index = thrd_recursion_depth[thread_id];
722 // If there are recursive calls, push more hashtables into the vector.
723 if (map->size() < (uint) index + 1) {
724 thrd_loc_inst_maps[thread_id]->push_back(new loc_inst_map_t(64));
725 thrd_inst_id_maps[thread_id]->push_back(new inst_id_map_t(64));
726 thrd_inst_pred_maps[thread_id]->push_back(new inst_pred_map_t(64));
729 ASSERT(map->size() == (uint) index + 1);
732 /* Reset elements of maps when threads exit functions */
733 void FuncNode::reset_local_maps(thread_id_t tid)
735 int thread_id = id_to_int(tid);
736 int index = thrd_recursion_depth[thread_id];
738 // When recursive call ends, keep only one hashtable in the vector
740 delete thrd_loc_inst_maps[thread_id]->back();
741 delete thrd_inst_id_maps[thread_id]->back();
742 delete thrd_inst_pred_maps[thread_id]->back();
744 thrd_loc_inst_maps[thread_id]->pop_back();
745 thrd_inst_id_maps[thread_id]->pop_back();
746 thrd_inst_pred_maps[thread_id]->pop_back();
748 thrd_loc_inst_maps[thread_id]->back()->reset();
749 thrd_inst_id_maps[thread_id]->back()->reset();
750 thrd_inst_pred_maps[thread_id]->back()->reset();
754 void FuncNode::init_predicate_tree_data_structure(thread_id_t tid)
756 int thread_id = id_to_int(tid);
757 int old_size = thrd_predicate_tree_position.size();
759 if (old_size < thread_id + 1) {
760 thrd_predicate_tree_position.resize(thread_id + 1);
761 thrd_predicate_trace.resize(thread_id + 1);
763 for (int i = old_size; i < thread_id + 1; i++) {
764 thrd_predicate_tree_position[i] = new ModelVector<Predicate *>();
765 thrd_predicate_trace[i] = new ModelVector<predicate_trace_t *>();
769 thrd_predicate_tree_position[thread_id]->push_back(predicate_tree_entry);
770 thrd_predicate_trace[thread_id]->push_back(new predicate_trace_t());
773 void FuncNode::reset_predicate_tree_data_structure(thread_id_t tid)
775 int thread_id = id_to_int(tid);
776 thrd_predicate_tree_position[thread_id]->pop_back();
778 // Free memories allocated in init_predicate_tree_data_structure
779 predicate_trace_t * trace = thrd_predicate_trace[thread_id]->back();
781 thrd_predicate_trace[thread_id]->pop_back();
784 /* Add FuncNodes that this node may follow */
785 void FuncNode::add_out_edge(FuncNode * other)
787 if ( !edge_table.contains(other) ) {
788 edge_table.put(other, OUT_EDGE);
789 out_edges.push_back(other);
793 edge_type_t edge = edge_table.get(other);
794 if (edge == IN_EDGE) {
795 edge_table.put(other, BI_EDGE);
796 out_edges.push_back(other);
800 /* Compute the distance between this FuncNode and the target node.
801 * Return -1 if the target node is unreachable or the actual distance
802 * is greater than max_step.
804 int FuncNode::compute_distance(FuncNode * target, int max_step)
808 else if (target == this)
811 SnapList<FuncNode *> queue;
812 HashTable<FuncNode *, int, uintptr_t, 0> distances(128);
814 queue.push_back(this);
815 distances.put(this, 0);
817 while (!queue.empty()) {
818 FuncNode * curr = queue.front();
820 int dist = distances.get(curr);
822 if (max_step <= dist)
825 ModelList<FuncNode *> * outEdges = curr->get_out_edges();
826 mllnode<FuncNode *> * it;
827 for (it = outEdges->begin();it != NULL;it = it->getNext()) {
828 FuncNode * out_node = it->getVal();
830 /* This node has not been visited before */
831 if ( !distances.contains(out_node) ) {
832 if (out_node == target)
835 queue.push_back(out_node);
836 distances.put(out_node, dist + 1);
841 /* Target node is unreachable */
845 void FuncNode::update_predicate_tree_weight(thread_id_t tid)
847 predicate_trace_t * trace = thrd_predicate_trace[id_to_int(tid)]->back();
849 // Update predicate weights based on prediate trace
850 for (mllnode<Predicate *> * rit = trace->end(); rit != NULL; rit = rit->getPrev()) {
851 Predicate * node = rit->getVal();
852 ModelVector<Predicate *> * children = node->get_children();
854 if (children->size() == 0) {
855 double weight = 100.0 / sqrt(node->get_expl_count() + node->get_fail_count() + 1);
856 node->set_weight(weight);
858 double weight_sum = 0.0;
859 for (uint i = 0;i < children->size();i++) {
860 Predicate * child = (*children)[i];
861 double weight = child->get_weight();
862 weight_sum += weight;
865 double average_weight = (double) weight_sum / (double) children->size();
866 double weight = average_weight * pow(0.9, node->get_depth());
867 node->set_weight(weight);
872 void FuncNode::print_predicate_tree()
874 model_print("digraph function_%s {\n", func_name);
875 predicate_tree_entry->print_pred_subtree();
876 predicate_tree_exit->print_predicate();
877 model_print("}\n"); // end of graph