- if ( loc_inst_map.contains(curr_inst->get_location()) ) {
- Predicate * new_pred1 = new Predicate(curr_inst);
- new_pred1->add_predicate(EQUALITY, curr_inst->get_location(), true);
-
- Predicate * new_pred2 = new Predicate(curr_inst);
- new_pred2->add_predicate(EQUALITY, curr_inst->get_location(), false);
-
- curr_pred->add_child(new_pred1);
- curr_pred->add_child(new_pred2);
-
- FuncInst * last_inst = loc_inst_map.get(curr_inst->get_location());
-
- uint64_t last_read = read_val_map->get(last_inst);
- if ( last_read == read_val_map->get(curr_inst) )
- curr_pred = new_pred1;
- else
- curr_pred = new_pred2;
- } else {
- Predicate * new_pred = new Predicate(curr_inst);
- curr_pred->add_child(new_pred);
- curr_pred = new_pred;
+ bool child_found = false;
+
+ /* check if a child with the same func_inst and corresponding predicate exists */
+ ModelVector<Predicate *> * children = curr_pred->get_children();
+ for (uint i = 0; i < children->size(); i++) {
+ Predicate * child = (*children)[i];
+ if (child->get_func_inst() != curr_inst)
+ continue;
+
+ PredExprSet * pred_expressions = child->get_pred_expressions();
+
+ /* no predicate, follow the only child */
+ if (pred_expressions->getSize() == 0) {
+ model_print("no predicate exists: ");
+ curr_inst->print();
+ curr_pred = child;
+ child_found = true;
+ break;
+ }
+ }
+
+ if (!child_found) {
+ if ( loc_inst_map.contains(curr_inst->get_location()) ) {
+ Predicate * new_pred1 = new Predicate(curr_inst);
+ new_pred1->add_predicate(EQUALITY, curr_inst->get_location(), true);
+
+ Predicate * new_pred2 = new Predicate(curr_inst);
+ new_pred2->add_predicate(EQUALITY, curr_inst->get_location(), false);
+
+ curr_pred->add_child(new_pred1);
+ curr_pred->add_child(new_pred2);
+
+ FuncInst * last_inst = loc_inst_map.get(curr_inst->get_location());
+ uint64_t last_read = read_val_map->get(last_inst);
+ if ( last_read == read_val_map->get(curr_inst) )
+ curr_pred = new_pred1;
+ else
+ curr_pred = new_pred2;
+ } else {
+ Predicate * new_pred = new Predicate(curr_inst);
+ curr_pred->add_child(new_pred);
+ curr_pred = new_pred;
+ }