6 #include "concretepredicate.h"
11 FuncNode::FuncNode(ModelHistory * history) :
16 thrd_recursion_depth(),
20 thrd_inst_pred_maps(),
23 thrd_predicate_tree_position(),
24 thrd_predicate_trace(),
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 read_locations = new loc_set_t();
36 write_locations = new loc_set_t();
37 val_loc_map = new HashTable<uint64_t, loc_set_t *, uint64_t, 0, snapshot_malloc, snapshot_calloc, snapshot_free, int64_hash>();
38 loc_may_equal_map = new HashTable<void *, loc_set_t *, uintptr_t, 0>();
40 //values_may_read_from = new value_set_t();
43 /* Reallocate snapshotted memories when new executions start */
44 void FuncNode::set_new_exec_flag()
46 read_locations = new loc_set_t();
47 write_locations = new loc_set_t();
48 val_loc_map = new HashTable<uint64_t, loc_set_t *, uint64_t, 0, snapshot_malloc, snapshot_calloc, snapshot_free, int64_hash>();
49 loc_may_equal_map = new HashTable<void *, loc_set_t *, uintptr_t, 0>();
51 //values_may_read_from = new value_set_t();
54 /* Check whether FuncInst with the same type, position, and location
55 * as act has been added to func_inst_map or not. If not, add it.
57 void FuncNode::add_inst(ModelAction *act)
60 const char * position = act->get_position();
62 /* THREAD* actions, ATOMIC_LOCK, ATOMIC_TRYLOCK, and ATOMIC_UNLOCK
63 * actions are not tagged with their source line numbers
68 FuncInst * func_inst = func_inst_map.get(position);
70 /* This position has not been inserted into hashtable before */
71 if (func_inst == NULL) {
72 func_inst = create_new_inst(act);
73 func_inst_map.put(position, func_inst);
77 /* Volatile variables that use ++ or -- syntax may result in read and write actions with the same position */
78 if (func_inst->get_type() != act->get_type()) {
79 FuncInst * collision_inst = func_inst->search_in_collision(act);
81 if (collision_inst == NULL) {
82 collision_inst = create_new_inst(act);
83 func_inst->add_to_collision(collision_inst);
86 func_inst = collision_inst;
90 ASSERT(func_inst->get_type() == act->get_type());
91 int curr_execution_number = model->get_execution_number();
93 /* Reset locations when new executions start */
94 if (func_inst->get_execution_number() != curr_execution_number) {
95 func_inst->set_location(act->get_location());
96 func_inst->set_execution_number(curr_execution_number);
99 /* Mark the memory location of such inst as not unique */
100 if (func_inst->get_location() != act->get_location())
101 func_inst->not_single_location();
104 FuncInst * FuncNode::create_new_inst(ModelAction * act)
106 FuncInst * func_inst = new FuncInst(act, this);
107 int exec_num = model->get_execution_number();
108 func_inst->set_execution_number(exec_num);
110 inst_list.push_back(func_inst);
116 /* Get the FuncInst with the same type, position, and location
119 * @return FuncInst with the same type, position, and location as act */
120 FuncInst * FuncNode::get_inst(ModelAction *act)
123 const char * position = act->get_position();
125 /* THREAD* actions, ATOMIC_LOCK, ATOMIC_TRYLOCK, and ATOMIC_UNLOCK
126 * actions are not tagged with their source line numbers
128 if (position == NULL)
131 FuncInst * inst = func_inst_map.get(position);
135 action_type inst_type = inst->get_type();
136 action_type act_type = act->get_type();
138 if (inst_type == act_type) {
141 /* RMWRCAS actions are converted to RMW or READ actions */
142 else if (inst_type == ATOMIC_RMWRCAS &&
143 (act_type == ATOMIC_RMW || act_type == ATOMIC_READ)) {
146 /* Return the FuncInst in the collision list */
148 return inst->search_in_collision(act);
152 void FuncNode::add_entry_inst(FuncInst * inst)
157 mllnode<FuncInst *> * it;
158 for (it = entry_insts.begin();it != NULL;it = it->getNext()) {
159 if (inst == it->getVal())
163 entry_insts.push_back(inst);
166 void FuncNode::function_entry_handler(thread_id_t tid)
169 init_local_maps(tid);
170 init_predicate_tree_data_structure(tid);
173 void FuncNode::function_exit_handler(thread_id_t tid)
175 int thread_id = id_to_int(tid);
177 reset_local_maps(tid);
179 thrd_recursion_depth[thread_id]--;
180 thrd_markers[thread_id]->pop_back();
182 Predicate * exit_pred = get_predicate_tree_position(tid);
183 if (exit_pred->get_exit() == NULL) {
184 // Exit predicate is unset yet
185 exit_pred->set_exit(predicate_tree_exit);
188 update_predicate_tree_weight(tid);
189 reset_predicate_tree_data_structure(tid);
193 * @brief Convert ModelAdtion list to FuncInst list
194 * @param act_list A list of ModelActions
196 void FuncNode::update_tree(ModelAction * act)
198 bool should_process = act->is_read() || act->is_write();
202 HashTable<void *, value_set_t *, uintptr_t, 0> * write_history = history->getWriteHistory();
204 /* build inst_list from act_list for later processing */
205 // func_inst_list_t inst_list;
207 FuncInst * func_inst = get_inst(act);
208 void * loc = act->get_location();
210 if (func_inst == NULL)
213 // inst_list.push_back(func_inst);
215 if (act->is_write()) {
216 if (!write_locations->contains(loc)) {
217 write_locations->add(loc);
218 history->update_loc_wr_func_nodes_map(loc, this);
221 // Do not process writes for now
225 if (act->is_read()) {
227 /* If func_inst may only read_from a single location, then:
229 * The first time an action reads from some location,
230 * import all the values that have been written to this
231 * location from ModelHistory and notify ModelHistory
232 * that this FuncNode may read from this location.
234 if (!read_locations->contains(loc) && func_inst->is_single_location()) {
235 read_locations->add(loc);
236 value_set_t * write_values = write_history->get(loc);
237 add_to_val_loc_map(write_values, loc);
238 history->update_loc_rd_func_nodes_map(loc, this);
242 // update_inst_tree(&inst_list); TODO
243 update_predicate_tree(act);
245 // print_predicate_tree();
249 * @brief Link FuncInsts in inst_list - add one FuncInst to another's predecessors and successors
250 * @param inst_list A list of FuncInsts
252 void FuncNode::update_inst_tree(func_inst_list_t * inst_list)
254 if (inst_list == NULL)
256 else if (inst_list->size() == 0)
260 sllnode<FuncInst *>* it = inst_list->begin();
261 sllnode<FuncInst *>* prev;
263 /* add the first instruction to the list of entry insts */
264 FuncInst * entry_inst = it->getVal();
265 add_entry_inst(entry_inst);
269 prev = it->getPrev();
271 FuncInst * prev_inst = prev->getVal();
272 FuncInst * curr_inst = it->getVal();
274 prev_inst->add_succ(curr_inst);
275 curr_inst->add_pred(prev_inst);
281 void FuncNode::update_predicate_tree(ModelAction * next_act)
283 thread_id_t tid = next_act->get_tid();
284 int thread_id = id_to_int(tid);
285 uint32_t this_marker = thrd_markers[thread_id]->back();
286 int recursion_depth = thrd_recursion_depth[thread_id];
288 loc_inst_map_t * loc_inst_map = thrd_loc_inst_maps[thread_id]->back();
289 inst_pred_map_t * inst_pred_map = thrd_inst_pred_maps[thread_id]->back();
290 inst_id_map_t * inst_id_map = thrd_inst_id_maps[thread_id]->back();
292 Predicate * curr_pred = get_predicate_tree_position(tid);
294 FuncInst * next_inst = get_inst(next_act);
295 next_inst->set_associated_read(tid, recursion_depth, this_marker, next_act->get_reads_from_value());
297 Predicate * unset_predicate = NULL;
298 bool branch_found = follow_branch(&curr_pred, next_inst, next_act, &unset_predicate);
300 // A branch with unset predicate expression is detected
301 if (!branch_found && unset_predicate != NULL) {
302 bool amended = amend_predicate_expr(curr_pred, next_inst, next_act);
306 curr_pred = unset_predicate;
312 if (!branch_found && inst_id_map->contains(next_inst)) {
313 FuncInst * curr_inst = curr_pred->get_func_inst();
314 uint32_t curr_id = inst_id_map->get(curr_inst);
315 uint32_t next_id = inst_id_map->get(next_inst);
317 if (curr_id >= next_id) {
318 Predicate * old_pred = inst_pred_map->get(next_inst);
319 Predicate * back_pred = old_pred->get_parent();
321 // Add to the set of backedges
322 curr_pred->add_backedge(back_pred);
323 curr_pred = back_pred;
329 // Generate new branches
331 SnapVector<struct half_pred_expr *> half_pred_expressions;
332 infer_predicates(next_inst, next_act, &half_pred_expressions);
333 generate_predicates(curr_pred, next_inst, &half_pred_expressions);
337 if (next_act->is_write())
338 curr_pred->set_write(true);
340 if (next_act->is_read()) {
341 /* Only need to store the locations of read actions */
342 loc_inst_map->put(next_inst->get_location(), next_inst);
345 inst_pred_map->put(next_inst, curr_pred);
346 set_predicate_tree_position(tid, curr_pred);
348 if (!inst_id_map->contains(next_inst))
349 inst_id_map->put(next_inst, inst_counter++);
351 curr_pred->incr_expl_count();
352 add_predicate_to_trace(tid, curr_pred);
357 /* Given curr_pred and next_inst, find the branch following curr_pred that
358 * contains next_inst and the correct predicate.
359 * @return true if branch found, false otherwise.
361 bool FuncNode::follow_branch(Predicate ** curr_pred, FuncInst * next_inst,
362 ModelAction * next_act, Predicate ** unset_predicate)
364 /* Check if a branch with func_inst and corresponding predicate exists */
365 bool branch_found = false;
366 thread_id_t tid = next_act->get_tid();
367 int thread_id = id_to_int(tid);
368 uint32_t this_marker = thrd_markers[thread_id]->back();
369 int recursion_depth = thrd_recursion_depth[thread_id];
371 ModelVector<Predicate *> * branches = (*curr_pred)->get_children();
372 for (uint i = 0;i < branches->size();i++) {
373 Predicate * branch = (*branches)[i];
374 if (branch->get_func_inst() != next_inst)
377 /* Check against predicate expressions */
378 bool predicate_correct = true;
379 PredExprSet * pred_expressions = branch->get_pred_expressions();
381 /* Only read and rmw actions my have unset predicate expressions */
382 if (pred_expressions->getSize() == 0) {
383 predicate_correct = false;
385 if (*unset_predicate == NULL)
386 *unset_predicate = branch;
393 PredExprSetIter * pred_expr_it = pred_expressions->iterator();
394 while (pred_expr_it->hasNext()) {
395 pred_expr * pred_expression = pred_expr_it->next();
396 uint64_t last_read, next_read;
399 switch(pred_expression->token) {
401 predicate_correct = true;
404 FuncInst * to_be_compared;
405 to_be_compared = pred_expression->func_inst;
406 ASSERT(to_be_compared != next_inst);
408 last_read = to_be_compared->get_associated_read(tid, recursion_depth, this_marker);
409 ASSERT(last_read != VALUE_NONE);
411 next_read = next_act->get_reads_from_value();
412 equality = (last_read == next_read);
413 if (equality != pred_expression->value)
414 predicate_correct = false;
418 next_read = next_act->get_reads_from_value();
419 // TODO: implement likely to be null
420 equality = ( (void*) (next_read & 0xffffffff) == NULL);
421 if (equality != pred_expression->value)
422 predicate_correct = false;
425 predicate_correct = false;
426 model_print("unkown predicate token\n");
433 if (predicate_correct) {
443 /* Infer predicate expressions, which are generated in FuncNode::generate_predicates */
444 void FuncNode::infer_predicates(FuncInst * next_inst, ModelAction * next_act,
445 SnapVector<struct half_pred_expr *> * half_pred_expressions)
447 void * loc = next_act->get_location();
448 int thread_id = id_to_int(next_act->get_tid());
449 loc_inst_map_t * loc_inst_map = thrd_loc_inst_maps[thread_id]->back();
451 if (next_inst->is_read()) {
453 if ( loc_inst_map->contains(loc) ) {
454 FuncInst * last_inst = loc_inst_map->get(loc);
455 struct half_pred_expr * expression = new half_pred_expr(EQUALITY, last_inst);
456 half_pred_expressions->push_back(expression);
457 } else if ( next_inst->is_single_location() ) {
458 loc_set_t * loc_may_equal = loc_may_equal_map->get(loc);
460 if (loc_may_equal != NULL) {
461 loc_set_iter * loc_it = loc_may_equal->iterator();
462 while (loc_it->hasNext()) {
463 void * neighbor = loc_it->next();
464 if (loc_inst_map->contains(neighbor)) {
465 FuncInst * last_inst = loc_inst_map->get(neighbor);
467 struct half_pred_expr * expression = new half_pred_expr(EQUALITY, last_inst);
468 half_pred_expressions->push_back(expression);
475 // next_inst is not single location
476 uint64_t read_val = next_act->get_reads_from_value();
478 // only infer NULLITY predicate when it is actually NULL.
479 if ( (void*)read_val == NULL) {
480 struct half_pred_expr * expression = new half_pred_expr(NULLITY, NULL);
481 half_pred_expressions->push_back(expression);
486 // TODO: do anything here?
490 /* Able to generate complex predicates when there are multiple predciate expressions */
491 void FuncNode::generate_predicates(Predicate * curr_pred, FuncInst * next_inst,
492 SnapVector<struct half_pred_expr *> * half_pred_expressions)
494 if (half_pred_expressions->size() == 0) {
495 Predicate * new_pred = new Predicate(next_inst);
496 curr_pred->add_child(new_pred);
497 new_pred->set_parent(curr_pred);
499 /* entry predicates and predicates containing pure write actions
500 * have no predicate expressions */
501 if ( curr_pred->is_entry_predicate() )
502 new_pred->add_predicate_expr(NOPREDICATE, NULL, true);
503 else if (next_inst->is_write()) {
504 /* next_inst->is_write() <==> pure writes */
505 new_pred->add_predicate_expr(NOPREDICATE, NULL, true);
511 SnapVector<Predicate *> predicates;
513 struct half_pred_expr * half_expr = (*half_pred_expressions)[0];
514 predicates.push_back(new Predicate(next_inst));
515 predicates.push_back(new Predicate(next_inst));
517 predicates[0]->add_predicate_expr(half_expr->token, half_expr->func_inst, true);
518 predicates[1]->add_predicate_expr(half_expr->token, half_expr->func_inst, false);
520 for (uint i = 1;i < half_pred_expressions->size();i++) {
521 half_expr = (*half_pred_expressions)[i];
523 uint old_size = predicates.size();
524 for (uint j = 0;j < old_size;j++) {
525 Predicate * pred = predicates[j];
526 Predicate * new_pred = new Predicate(next_inst);
527 new_pred->copy_predicate_expr(pred);
529 pred->add_predicate_expr(half_expr->token, half_expr->func_inst, true);
530 new_pred->add_predicate_expr(half_expr->token, half_expr->func_inst, false);
532 predicates.push_back(new_pred);
536 for (uint i = 0;i < predicates.size();i++) {
537 Predicate * pred= predicates[i];
538 curr_pred->add_child(pred);
539 pred->set_parent(curr_pred);
542 /* Free memories allocated by infer_predicate */
543 for (uint i = 0;i < half_pred_expressions->size();i++) {
544 struct half_pred_expr * tmp = (*half_pred_expressions)[i];
549 /* Amend predicates that contain no predicate expressions. Currenlty only amend with NULLITY predicates */
550 bool FuncNode::amend_predicate_expr(Predicate * curr_pred, FuncInst * next_inst, ModelAction * next_act)
552 ModelVector<Predicate *> * children = curr_pred->get_children();
554 Predicate * unset_pred = NULL;
555 for (uint i = 0;i < children->size();i++) {
556 Predicate * child = (*children)[i];
557 if (child->get_func_inst() == next_inst) {
563 uint64_t read_val = next_act->get_reads_from_value();
565 // only generate NULLITY predicate when it is actually NULL.
566 if ( !next_inst->is_single_location() && (void*)read_val == NULL ) {
567 Predicate * new_pred = new Predicate(next_inst);
569 curr_pred->add_child(new_pred);
570 new_pred->set_parent(curr_pred);
572 unset_pred->add_predicate_expr(NULLITY, NULL, false);
573 new_pred->add_predicate_expr(NULLITY, NULL, true);
581 void FuncNode::add_to_val_loc_map(uint64_t val, void * loc)
583 loc_set_t * locations = val_loc_map->get(val);
585 if (locations == NULL) {
586 locations = new loc_set_t();
587 val_loc_map->put(val, locations);
590 update_loc_may_equal_map(loc, locations);
592 // values_may_read_from->add(val);
595 void FuncNode::add_to_val_loc_map(value_set_t * values, void * loc)
600 value_set_iter * it = values->iterator();
601 while (it->hasNext()) {
602 uint64_t val = it->next();
603 add_to_val_loc_map(val, loc);
609 void FuncNode::update_loc_may_equal_map(void * new_loc, loc_set_t * old_locations)
611 if ( old_locations->contains(new_loc) )
614 loc_set_t * neighbors = loc_may_equal_map->get(new_loc);
616 if (neighbors == NULL) {
617 neighbors = new loc_set_t();
618 loc_may_equal_map->put(new_loc, neighbors);
621 loc_set_iter * loc_it = old_locations->iterator();
622 while (loc_it->hasNext()) {
623 // new_loc: { old_locations, ... }
624 void * member = loc_it->next();
625 neighbors->add(member);
627 // for each i in old_locations, i : { new_loc, ... }
628 loc_set_t * _neighbors = loc_may_equal_map->get(member);
629 if (_neighbors == NULL) {
630 _neighbors = new loc_set_t();
631 loc_may_equal_map->put(member, _neighbors);
633 _neighbors->add(new_loc);
639 void FuncNode::set_predicate_tree_position(thread_id_t tid, Predicate * pred)
641 int thread_id = id_to_int(tid);
642 ModelVector<Predicate *> * stack = thrd_predicate_tree_position[thread_id];
643 (*stack)[stack->size() - 1] = pred;
646 /* @return The position of a thread in a predicate tree */
647 Predicate * FuncNode::get_predicate_tree_position(thread_id_t tid)
649 int thread_id = id_to_int(tid);
650 return thrd_predicate_tree_position[thread_id]->back();
653 void FuncNode::add_predicate_to_trace(thread_id_t tid, Predicate * pred)
655 int thread_id = id_to_int(tid);
656 thrd_predicate_trace[thread_id]->back()->push_back(pred);
659 void FuncNode::init_marker(thread_id_t tid)
663 int thread_id = id_to_int(tid);
664 int old_size = thrd_markers.size();
666 if (old_size < thread_id + 1) {
667 thrd_markers.resize(thread_id + 1);
669 for (int i = old_size; i < thread_id + 1; i++) {
670 thrd_markers[i] = new ModelVector<uint32_t>();
671 thrd_recursion_depth.push_back(-1);
675 thrd_markers[thread_id]->push_back(marker);
676 thrd_recursion_depth[thread_id]++;
679 uint32_t FuncNode::get_marker(thread_id_t tid)
681 int thread_id = id_to_int(tid);
682 return thrd_markers[thread_id]->back();
685 int FuncNode::get_recursion_depth(thread_id_t tid)
687 return thrd_recursion_depth[id_to_int(tid)];
690 /* Make sure elements of maps are initialized properly when threads enter functions */
691 void FuncNode::init_local_maps(thread_id_t tid)
693 int thread_id = id_to_int(tid);
694 int old_size = thrd_loc_inst_maps.size();
696 if (old_size < thread_id + 1) {
697 int new_size = thread_id + 1;
699 thrd_loc_inst_maps.resize(new_size);
700 thrd_inst_id_maps.resize(new_size);
701 thrd_inst_pred_maps.resize(new_size);
703 for (int i = old_size; i < new_size; i++) {
704 thrd_loc_inst_maps[i] = new ModelVector<loc_inst_map_t *>;
705 thrd_inst_id_maps[i] = new ModelVector<inst_id_map_t *>;
706 thrd_inst_pred_maps[i] = new ModelVector<inst_pred_map_t *>;
710 ModelVector<loc_inst_map_t *> * map = thrd_loc_inst_maps[thread_id];
711 int index = thrd_recursion_depth[thread_id];
713 // If there are recursive calls, push more hashtables into the vector.
714 if (map->size() < (uint) index + 1) {
715 thrd_loc_inst_maps[thread_id]->push_back(new loc_inst_map_t(64));
716 thrd_inst_id_maps[thread_id]->push_back(new inst_id_map_t(64));
717 thrd_inst_pred_maps[thread_id]->push_back(new inst_pred_map_t(64));
720 ASSERT(map->size() == (uint) index + 1);
723 /* Reset elements of maps when threads exit functions */
724 void FuncNode::reset_local_maps(thread_id_t tid)
726 int thread_id = id_to_int(tid);
727 int index = thrd_recursion_depth[thread_id];
729 // When recursive call ends, keep only one hashtable in the vector
731 delete thrd_loc_inst_maps[thread_id]->back();
732 delete thrd_inst_id_maps[thread_id]->back();
733 delete thrd_inst_pred_maps[thread_id]->back();
735 thrd_loc_inst_maps[thread_id]->pop_back();
736 thrd_inst_id_maps[thread_id]->pop_back();
737 thrd_inst_pred_maps[thread_id]->pop_back();
739 thrd_loc_inst_maps[thread_id]->back()->reset();
740 thrd_inst_id_maps[thread_id]->back()->reset();
741 thrd_inst_pred_maps[thread_id]->back()->reset();
745 void FuncNode::init_predicate_tree_data_structure(thread_id_t tid)
747 int thread_id = id_to_int(tid);
748 int old_size = thrd_predicate_tree_position.size();
750 if (old_size < thread_id + 1) {
751 thrd_predicate_tree_position.resize(thread_id + 1);
752 thrd_predicate_trace.resize(thread_id + 1);
754 for (int i = old_size; i < thread_id + 1; i++) {
755 thrd_predicate_tree_position[i] = new ModelVector<Predicate *>();
756 thrd_predicate_trace[i] = new ModelVector<predicate_trace_t *>();
760 thrd_predicate_tree_position[thread_id]->push_back(predicate_tree_entry);
761 thrd_predicate_trace[thread_id]->push_back(new predicate_trace_t());
764 void FuncNode::reset_predicate_tree_data_structure(thread_id_t tid)
766 int thread_id = id_to_int(tid);
767 thrd_predicate_tree_position[thread_id]->pop_back();
769 // Free memories allocated in init_predicate_tree_data_structure
770 predicate_trace_t * trace = thrd_predicate_trace[thread_id]->back();
772 thrd_predicate_trace[thread_id]->pop_back();
775 /* Add FuncNodes that this node may follow */
776 void FuncNode::add_out_edge(FuncNode * other)
778 if ( !edge_table.contains(other) ) {
779 edge_table.put(other, OUT_EDGE);
780 out_edges.push_back(other);
784 edge_type_t edge = edge_table.get(other);
785 if (edge == IN_EDGE) {
786 edge_table.put(other, BI_EDGE);
787 out_edges.push_back(other);
791 /* Compute the distance between this FuncNode and the target node.
792 * Return -1 if the target node is unreachable or the actual distance
793 * is greater than max_step.
795 int FuncNode::compute_distance(FuncNode * target, int max_step)
799 else if (target == this)
802 SnapList<FuncNode *> queue;
803 HashTable<FuncNode *, int, uintptr_t, 0> distances(128);
805 queue.push_back(this);
806 distances.put(this, 0);
808 while (!queue.empty()) {
809 FuncNode * curr = queue.front();
811 int dist = distances.get(curr);
813 if (max_step <= dist)
816 ModelList<FuncNode *> * outEdges = curr->get_out_edges();
817 mllnode<FuncNode *> * it;
818 for (it = outEdges->begin();it != NULL;it = it->getNext()) {
819 FuncNode * out_node = it->getVal();
821 /* This node has not been visited before */
822 if ( !distances.contains(out_node) ) {
823 if (out_node == target)
826 queue.push_back(out_node);
827 distances.put(out_node, dist + 1);
832 /* Target node is unreachable */
836 void FuncNode::update_predicate_tree_weight(thread_id_t tid)
838 predicate_trace_t * trace = thrd_predicate_trace[id_to_int(tid)]->back();
840 // Update predicate weights based on prediate trace
841 for (mllnode<Predicate *> * rit = trace->end(); rit != NULL; rit = rit->getPrev()) {
842 Predicate * node = rit->getVal();
843 ModelVector<Predicate *> * children = node->get_children();
845 if (children->size() == 0) {
846 double weight = 100.0 / sqrt(node->get_expl_count() + node->get_fail_count() + 1);
847 node->set_weight(weight);
849 double weight_sum = 0.0;
850 for (uint i = 0;i < children->size();i++) {
851 Predicate * child = (*children)[i];
852 double weight = child->get_weight();
853 weight_sum += weight;
856 double average_weight = (double) weight_sum / (double) children->size();
857 double weight = average_weight * pow(0.9, node->get_depth());
858 node->set_weight(weight);
863 void FuncNode::print_predicate_tree()
865 model_print("digraph function_%s {\n", func_name);
866 predicate_tree_entry->print_pred_subtree();
867 predicate_tree_exit->print_predicate();
868 model_print("}\n"); // end of graph