6 #include "concretepredicate.h"
11 FuncNode::FuncNode(ModelHistory * history) :
21 predicate_tree_position(),
28 predicate_tree_entry = new Predicate(NULL, true);
29 predicate_tree_entry->add_predicate_expr(NOPREDICATE, NULL, true);
31 predicate_tree_exit = new Predicate(NULL, false, true);
32 predicate_tree_exit->set_depth(MAX_DEPTH);
34 /* Snapshot data structures below */
35 action_list_buffer = new SnapList<action_list_t *>();
36 read_locations = new loc_set_t();
37 write_locations = new loc_set_t();
38 val_loc_map = new HashTable<uint64_t, loc_set_t *, uint64_t, 0, snapshot_malloc, snapshot_calloc, snapshot_free, int64_hash>();
39 loc_may_equal_map = new HashTable<void *, loc_set_t *, uintptr_t, 0>();
41 //values_may_read_from = new value_set_t();
44 /* Reallocate snapshotted memories when new executions start */
45 void FuncNode::set_new_exec_flag()
47 action_list_buffer = new SnapList<action_list_t *>();
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);
155 void FuncNode::add_entry_inst(FuncInst * inst)
160 mllnode<FuncInst *> * it;
161 for (it = entry_insts.begin();it != NULL;it = it->getNext()) {
162 if (inst == it->getVal())
166 entry_insts.push_back(inst);
170 * @brief Convert ModelAdtion list to FuncInst list
171 * @param act_list A list of ModelActions
173 void FuncNode::update_tree(action_list_t * act_list)
175 if (act_list == NULL || act_list->size() == 0)
178 HashTable<void *, value_set_t *, uintptr_t, 0> * write_history = history->getWriteHistory();
180 /* build inst_list from act_list for later processing */
181 func_inst_list_t inst_list;
182 action_list_t rw_act_list;
184 for (sllnode<ModelAction *> * it = act_list->begin();it != NULL;it = it->getNext()) {
185 ModelAction * act = it->getVal();
186 FuncInst * func_inst = get_inst(act);
187 void * loc = act->get_location();
189 if (func_inst == NULL)
192 inst_list.push_back(func_inst);
193 bool act_added = false;
195 if (act->is_write()) {
196 rw_act_list.push_back(act);
198 if (!write_locations->contains(loc)) {
199 write_locations->add(loc);
200 history->update_loc_wr_func_nodes_map(loc, this);
204 if (act->is_read()) {
206 rw_act_list.push_back(act);
208 /* If func_inst may only read_from a single location, then:
210 * The first time an action reads from some location,
211 * import all the values that have been written to this
212 * location from ModelHistory and notify ModelHistory
213 * that this FuncNode may read from this location.
215 if (!read_locations->contains(loc) && func_inst->is_single_location()) {
216 read_locations->add(loc);
217 value_set_t * write_values = write_history->get(loc);
218 add_to_val_loc_map(write_values, loc);
219 history->update_loc_rd_func_nodes_map(loc, this);
224 // model_print("function %s\n", func_name);
225 // print_val_loc_map();
227 update_inst_tree(&inst_list);
228 update_predicate_tree(&rw_act_list);
230 // print_predicate_tree();
234 * @brief Link FuncInsts in inst_list - add one FuncInst to another's predecessors and successors
235 * @param inst_list A list of FuncInsts
237 void FuncNode::update_inst_tree(func_inst_list_t * inst_list)
239 if (inst_list == NULL)
241 else if (inst_list->size() == 0)
245 sllnode<FuncInst *>* it = inst_list->begin();
246 sllnode<FuncInst *>* prev;
248 /* add the first instruction to the list of entry insts */
249 FuncInst * entry_inst = it->getVal();
250 add_entry_inst(entry_inst);
254 prev = it->getPrev();
256 FuncInst * prev_inst = prev->getVal();
257 FuncInst * curr_inst = it->getVal();
259 prev_inst->add_succ(curr_inst);
260 curr_inst->add_pred(prev_inst);
266 void FuncNode::update_predicate_tree(action_list_t * act_list)
268 if (act_list == NULL || act_list->size() == 0)
272 uint32_t inst_counter = 0;
276 inst_pred_map.reset();
279 // Clear the set of leaves encountered in this path
280 leaves_tmp_storage.clear();
282 sllnode<ModelAction *> *it = act_list->begin();
283 Predicate * curr_pred = predicate_tree_entry;
285 ModelAction * next_act = it->getVal();
286 FuncInst * next_inst = get_inst(next_act);
287 next_inst->set_associated_act(next_act, marker);
289 Predicate * unset_predicate = NULL;
290 bool branch_found = follow_branch(&curr_pred, next_inst, next_act, &unset_predicate);
292 // A branch with unset predicate expression is detected
293 if (!branch_found && unset_predicate != NULL) {
294 bool amended = amend_predicate_expr(curr_pred, next_inst, next_act);
298 curr_pred = unset_predicate;
304 if (!branch_found && inst_id_map.contains(next_inst)) {
305 FuncInst * curr_inst = curr_pred->get_func_inst();
306 uint32_t curr_id = inst_id_map.get(curr_inst);
307 uint32_t next_id = inst_id_map.get(next_inst);
309 if (curr_id >= next_id) {
310 Predicate * old_pred = inst_pred_map.get(next_inst);
311 Predicate * back_pred = old_pred->get_parent();
313 // For updating weights
314 leaves_tmp_storage.push_back(curr_pred);
316 // Add to the set of backedges
317 curr_pred->add_backedge(back_pred);
318 curr_pred = back_pred;
323 // Generate new branches
325 SnapVector<struct half_pred_expr *> half_pred_expressions;
326 infer_predicates(next_inst, next_act, &half_pred_expressions);
327 generate_predicates(curr_pred, next_inst, &half_pred_expressions);
331 if (next_act->is_write())
332 curr_pred->set_write(true);
334 if (next_act->is_read()) {
335 /* Only need to store the locations of read actions */
336 loc_act_map.put(next_act->get_location(), next_act);
339 inst_pred_map.put(next_inst, curr_pred);
340 if (!inst_id_map.contains(next_inst))
341 inst_id_map.put(next_inst, inst_counter++);
344 curr_pred->incr_expl_count();
347 if (curr_pred->get_exit() == NULL) {
348 // Exit predicate is unset yet
349 curr_pred->set_exit(predicate_tree_exit);
352 leaves_tmp_storage.push_back(curr_pred);
353 update_predicate_tree_weight();
356 /* Given curr_pred and next_inst, find the branch following curr_pred that
357 * contains next_inst and the correct predicate.
358 * @return true if branch found, false otherwise.
360 bool FuncNode::follow_branch(Predicate ** curr_pred, FuncInst * next_inst,
361 ModelAction * next_act, Predicate ** unset_predicate)
363 /* Check if a branch with func_inst and corresponding predicate exists */
364 bool branch_found = false;
365 ModelVector<Predicate *> * branches = (*curr_pred)->get_children();
366 for (uint i = 0;i < branches->size();i++) {
367 Predicate * branch = (*branches)[i];
368 if (branch->get_func_inst() != next_inst)
371 /* Check against predicate expressions */
372 bool predicate_correct = true;
373 PredExprSet * pred_expressions = branch->get_pred_expressions();
375 /* Only read and rmw actions my have unset predicate expressions */
376 if (pred_expressions->getSize() == 0) {
377 predicate_correct = false;
378 if (*unset_predicate == NULL)
379 *unset_predicate = branch;
386 PredExprSetIter * pred_expr_it = pred_expressions->iterator();
387 while (pred_expr_it->hasNext()) {
388 pred_expr * pred_expression = pred_expr_it->next();
389 uint64_t last_read, next_read;
392 switch(pred_expression->token) {
394 predicate_correct = true;
397 FuncInst * to_be_compared;
398 ModelAction * last_act;
400 to_be_compared = pred_expression->func_inst;
401 last_act = to_be_compared->get_associated_act(marker);
403 last_read = last_act->get_reads_from_value();
404 next_read = next_act->get_reads_from_value();
405 equality = (last_read == next_read);
406 if (equality != pred_expression->value)
407 predicate_correct = false;
411 next_read = next_act->get_reads_from_value();
412 // TODO: implement likely to be null
413 equality = ( (void*) (next_read & 0xffffffff) == NULL);
414 if (equality != pred_expression->value)
415 predicate_correct = false;
418 predicate_correct = false;
419 model_print("unkown predicate token\n");
426 if (predicate_correct) {
436 /* Infer predicate expressions, which are generated in FuncNode::generate_predicates */
437 void FuncNode::infer_predicates(FuncInst * next_inst, ModelAction * next_act,
438 SnapVector<struct half_pred_expr *> * half_pred_expressions)
440 void * loc = next_act->get_location();
442 if (next_inst->is_read()) {
444 if ( loc_act_map.contains(loc) ) {
445 ModelAction * last_act = loc_act_map.get(loc);
446 FuncInst * last_inst = get_inst(last_act);
447 struct half_pred_expr * expression = new half_pred_expr(EQUALITY, last_inst);
448 half_pred_expressions->push_back(expression);
449 } else if ( next_inst->is_single_location() ) {
450 loc_set_t * loc_may_equal = loc_may_equal_map->get(loc);
452 if (loc_may_equal != NULL) {
453 loc_set_iter * loc_it = loc_may_equal->iterator();
454 while (loc_it->hasNext()) {
455 void * neighbor = loc_it->next();
456 if (loc_act_map.contains(neighbor)) {
457 ModelAction * last_act = loc_act_map.get(neighbor);
458 FuncInst * last_inst = get_inst(last_act);
460 struct half_pred_expr * expression = new half_pred_expr(EQUALITY, last_inst);
461 half_pred_expressions->push_back(expression);
468 // next_inst is not single location
469 uint64_t read_val = next_act->get_reads_from_value();
471 // only infer NULLITY predicate when it is actually NULL.
472 if ( (void*)read_val == NULL) {
473 struct half_pred_expr * expression = new half_pred_expr(NULLITY, NULL);
474 half_pred_expressions->push_back(expression);
479 // TODO: do anything here?
483 /* Able to generate complex predicates when there are multiple predciate expressions */
484 void FuncNode::generate_predicates(Predicate * curr_pred, FuncInst * next_inst,
485 SnapVector<struct half_pred_expr *> * half_pred_expressions)
487 if (half_pred_expressions->size() == 0) {
488 Predicate * new_pred = new Predicate(next_inst);
489 curr_pred->add_child(new_pred);
490 new_pred->set_parent(curr_pred);
492 /* Maintain predicate leaves */
493 predicate_leaves.add(new_pred);
494 predicate_leaves.remove(curr_pred);
496 /* entry predicates and predicates containing pure write actions
497 * have no predicate expressions */
498 if ( curr_pred->is_entry_predicate() )
499 new_pred->add_predicate_expr(NOPREDICATE, NULL, true);
500 else if (next_inst->is_write()) {
501 /* next_inst->is_write() <==> pure writes */
502 new_pred->add_predicate_expr(NOPREDICATE, NULL, true);
508 SnapVector<Predicate *> predicates;
510 struct half_pred_expr * half_expr = (*half_pred_expressions)[0];
511 predicates.push_back(new Predicate(next_inst));
512 predicates.push_back(new Predicate(next_inst));
514 predicates[0]->add_predicate_expr(half_expr->token, half_expr->func_inst, true);
515 predicates[1]->add_predicate_expr(half_expr->token, half_expr->func_inst, false);
517 for (uint i = 1;i < half_pred_expressions->size();i++) {
518 half_expr = (*half_pred_expressions)[i];
520 uint old_size = predicates.size();
521 for (uint j = 0;j < old_size;j++) {
522 Predicate * pred = predicates[j];
523 Predicate * new_pred = new Predicate(next_inst);
524 new_pred->copy_predicate_expr(pred);
526 pred->add_predicate_expr(half_expr->token, half_expr->func_inst, true);
527 new_pred->add_predicate_expr(half_expr->token, half_expr->func_inst, false);
529 predicates.push_back(new_pred);
533 for (uint i = 0;i < predicates.size();i++) {
534 Predicate * pred= predicates[i];
535 curr_pred->add_child(pred);
536 pred->set_parent(curr_pred);
538 /* Add new predicate leaves */
539 predicate_leaves.add(pred);
542 /* Remove predicate node that has children */
543 predicate_leaves.remove(curr_pred);
545 /* Free memories allocated by infer_predicate */
546 for (uint i = 0;i < half_pred_expressions->size();i++) {
547 struct half_pred_expr * tmp = (*half_pred_expressions)[i];
552 /* Amend predicates that contain no predicate expressions. Currenlty only amend with NULLITY predicates */
553 bool FuncNode::amend_predicate_expr(Predicate * curr_pred, FuncInst * next_inst, ModelAction * next_act)
555 ModelVector<Predicate *> * children = curr_pred->get_children();
556 ASSERT(children->size() == 1);
558 // there should only be only child
559 Predicate * unset_pred = (*children)[0];
560 uint64_t read_val = next_act->get_reads_from_value();
562 // only generate NULLITY predicate when it is actually NULL.
563 if ( !next_inst->is_single_location() && (void*)read_val == NULL ) {
564 Predicate * new_pred = new Predicate(next_inst);
566 curr_pred->add_child(new_pred);
567 new_pred->set_parent(curr_pred);
569 unset_pred->add_predicate_expr(NULLITY, NULL, false);
570 new_pred->add_predicate_expr(NULLITY, NULL, true);
578 void FuncNode::add_to_val_loc_map(uint64_t val, void * loc)
580 loc_set_t * locations = val_loc_map->get(val);
582 if (locations == NULL) {
583 locations = new loc_set_t();
584 val_loc_map->put(val, locations);
587 update_loc_may_equal_map(loc, locations);
589 // values_may_read_from->add(val);
592 void FuncNode::add_to_val_loc_map(value_set_t * values, void * loc)
597 value_set_iter * it = values->iterator();
598 while (it->hasNext()) {
599 uint64_t val = it->next();
600 add_to_val_loc_map(val, loc);
606 void FuncNode::update_loc_may_equal_map(void * new_loc, loc_set_t * old_locations)
608 if ( old_locations->contains(new_loc) )
611 loc_set_t * neighbors = loc_may_equal_map->get(new_loc);
613 if (neighbors == NULL) {
614 neighbors = new loc_set_t();
615 loc_may_equal_map->put(new_loc, neighbors);
618 loc_set_iter * loc_it = old_locations->iterator();
619 while (loc_it->hasNext()) {
620 // new_loc: { old_locations, ... }
621 void * member = loc_it->next();
622 neighbors->add(member);
624 // for each i in old_locations, i : { new_loc, ... }
625 loc_set_t * _neighbors = loc_may_equal_map->get(member);
626 if (_neighbors == NULL) {
627 _neighbors = new loc_set_t();
628 loc_may_equal_map->put(member, _neighbors);
630 _neighbors->add(new_loc);
636 /* Every time a thread enters a function, set its position to the predicate tree entry */
637 void FuncNode::init_predicate_tree_position(thread_id_t tid)
639 int thread_id = id_to_int(tid);
640 if (predicate_tree_position.size() <= (uint) thread_id)
641 predicate_tree_position.resize(thread_id + 1);
643 predicate_tree_position[thread_id] = predicate_tree_entry;
646 void FuncNode::set_predicate_tree_position(thread_id_t tid, Predicate * pred)
648 int thread_id = id_to_int(tid);
649 predicate_tree_position[thread_id] = pred;
652 /* @return The position of a thread in a predicate tree */
653 Predicate * FuncNode::get_predicate_tree_position(thread_id_t tid)
655 int thread_id = id_to_int(tid);
656 return predicate_tree_position[thread_id];
659 /* Make sure elements of thrd_inst_act_map are initialized properly when threads enter functions */
660 void FuncNode::init_inst_act_map(thread_id_t tid)
662 int thread_id = id_to_int(tid);
663 SnapVector<inst_act_map_t *> * thrd_inst_act_map = history->getThrdInstActMap(func_id);
664 uint old_size = thrd_inst_act_map->size();
666 if (thrd_inst_act_map->size() <= (uint) thread_id) {
667 uint new_size = thread_id + 1;
668 thrd_inst_act_map->resize(new_size);
670 for (uint i = old_size;i < new_size;i++)
671 (*thrd_inst_act_map)[i] = new inst_act_map_t(128);
675 /* Reset elements of thrd_inst_act_map when threads exit functions */
676 void FuncNode::reset_inst_act_map(thread_id_t tid)
678 int thread_id = id_to_int(tid);
679 SnapVector<inst_act_map_t *> * thrd_inst_act_map = history->getThrdInstActMap(func_id);
681 inst_act_map_t * map = (*thrd_inst_act_map)[thread_id];
685 void FuncNode::update_inst_act_map(thread_id_t tid, ModelAction * read_act)
687 int thread_id = id_to_int(tid);
688 SnapVector<inst_act_map_t *> * thrd_inst_act_map = history->getThrdInstActMap(func_id);
690 inst_act_map_t * map = (*thrd_inst_act_map)[thread_id];
691 FuncInst * read_inst = get_inst(read_act);
692 map->put(read_inst, read_act);
695 inst_act_map_t * FuncNode::get_inst_act_map(thread_id_t tid)
697 int thread_id = id_to_int(tid);
698 SnapVector<inst_act_map_t *> * thrd_inst_act_map = history->getThrdInstActMap(func_id);
700 return (*thrd_inst_act_map)[thread_id];
703 /* Add FuncNodes that this node may follow */
704 void FuncNode::add_out_edge(FuncNode * other)
706 if ( !edge_table.contains(other) ) {
707 edge_table.put(other, OUT_EDGE);
708 out_edges.push_back(other);
712 edge_type_t edge = edge_table.get(other);
713 if (edge == IN_EDGE) {
714 edge_table.put(other, BI_EDGE);
715 out_edges.push_back(other);
719 /* Compute the distance between this FuncNode and the target node.
720 * Return -1 if the target node is unreachable or the actual distance
721 * is greater than max_step.
723 int FuncNode::compute_distance(FuncNode * target, int max_step)
727 else if (target == this)
730 SnapList<FuncNode *> queue;
731 HashTable<FuncNode *, int, uintptr_t, 0> distances(128);
733 queue.push_back(this);
734 distances.put(this, 0);
736 while (!queue.empty()) {
737 FuncNode * curr = queue.front();
739 int dist = distances.get(curr);
741 if (max_step <= dist)
744 ModelList<FuncNode *> * outEdges = curr->get_out_edges();
745 mllnode<FuncNode *> * it;
746 for (it = outEdges->begin();it != NULL;it = it->getNext()) {
747 FuncNode * out_node = it->getVal();
749 /* This node has not been visited before */
750 if ( !distances.contains(out_node) ) {
751 if (out_node == target)
754 queue.push_back(out_node);
755 distances.put(out_node, dist + 1);
760 /* Target node is unreachable */
764 /* Implement quick sort to sort leaves before assigning base scores */
765 template<typename _Tp>
766 static int partition(ModelVector<_Tp *> * arr, int low, int high)
768 unsigned int pivot = (*arr)[high]->get_depth();
771 for (int j = low; j <= high - 1; j++) {
772 if ( (*arr)[j]->get_depth() < pivot ) {
774 _Tp * tmp = (*arr)[i];
775 (*arr)[i] = (*arr)[j];
780 _Tp * tmp = (*arr)[i + 1];
781 (*arr)[i + 1] = (*arr)[high];
787 /* Implement quick sort to sort leaves before assigning base scores */
788 template<typename _Tp>
789 static void quickSort(ModelVector<_Tp *> * arr, int low, int high)
792 int pi = partition(arr, low, high);
794 quickSort(arr, low, pi - 1);
795 quickSort(arr, pi + 1, high);
799 void FuncNode::assign_initial_weight()
801 PredSetIter * it = predicate_leaves.iterator();
802 leaves_tmp_storage.clear();
804 while (it->hasNext()) {
805 Predicate * pred = it->next();
806 double weight = 100.0 / sqrt(pred->get_expl_count() + 1);
807 pred->set_weight(weight);
808 leaves_tmp_storage.push_back(pred);
812 quickSort(&leaves_tmp_storage, 0, leaves_tmp_storage.size() - 1);
814 // assign scores for internal nodes;
815 while ( !leaves_tmp_storage.empty() ) {
816 Predicate * leaf = leaves_tmp_storage.back();
817 leaves_tmp_storage.pop_back();
819 Predicate * curr = leaf->get_parent();
820 while (curr != NULL) {
821 if (curr->get_weight() != 0) {
826 ModelVector<Predicate *> * children = curr->get_children();
827 double weight_sum = 0;
828 bool has_unassigned_node = false;
830 for (uint i = 0; i < children->size(); i++) {
831 Predicate * child = (*children)[i];
833 // If a child has unassigned weight
834 double weight = child->get_weight();
836 has_unassigned_node = true;
839 weight_sum += weight;
842 if (!has_unassigned_node) {
843 double average_weight = (double) weight_sum / (double) children->size();
844 double weight = average_weight * pow(0.9, curr->get_depth());
845 curr->set_weight(weight);
849 curr = curr->get_parent();
854 void FuncNode::update_predicate_tree_weight()
857 // Predicate tree is initially built
858 assign_initial_weight();
862 weight_debug_vec.clear();
864 quickSort(&leaves_tmp_storage, 0, leaves_tmp_storage.size() - 1);
865 for (uint i = 0; i < leaves_tmp_storage.size(); i++) {
866 Predicate * pred = leaves_tmp_storage[i];
867 double weight = 100.0 / sqrt(pred->get_expl_count() + 1);
868 pred->set_weight(weight);
871 // Update weights in internal nodes
872 while ( !leaves_tmp_storage.empty() ) {
873 Predicate * leaf = leaves_tmp_storage.back();
874 leaves_tmp_storage.pop_back();
876 Predicate * curr = leaf->get_parent();
877 while (curr != NULL) {
878 ModelVector<Predicate *> * children = curr->get_children();
879 double weight_sum = 0;
880 bool has_unassigned_node = false;
882 for (uint i = 0; i < children->size(); i++) {
883 Predicate * child = (*children)[i];
885 double weight = child->get_weight();
887 weight_sum += weight;
888 else if ( predicate_leaves.contains(child) ) {
889 // If this child is a leaf
890 double weight = 100.0 / sqrt(child->get_expl_count() + 1);
891 child->set_weight(weight);
892 weight_sum += weight;
894 has_unassigned_node = true;
895 weight_debug_vec.push_back(child); // For debugging purpose
900 if (!has_unassigned_node) {
901 double average_weight = (double) weight_sum / (double) children->size();
902 double weight = average_weight * pow(0.9, curr->get_depth());
903 curr->set_weight(weight);
907 curr = curr->get_parent();
911 for (uint i = 0; i < weight_debug_vec.size(); i++) {
912 Predicate * tmp = weight_debug_vec[i];
913 ASSERT( tmp->get_weight() != 0 );
917 void FuncNode::print_predicate_tree()
919 model_print("digraph function_%s {\n", func_name);
920 predicate_tree_entry->print_pred_subtree();
921 predicate_tree_exit->print_predicate();
922 model_print("}\n"); // end of graph