+
+/* Remove writes from the rf_set that do not satisfie the selected predicate,
+ * and store them in thrd_pruned_writes
+ *
+ * @return true if rf_set is pruned
+ */
+bool NewFuzzer::prune_writes(thread_id_t tid, Predicate * pred,
+ SnapVector<ModelAction *> * rf_set, inst_act_map_t * inst_act_map)
+{
+ if (pred == NULL)
+ return false;
+
+ PredExprSet * pred_expressions = pred->get_pred_expressions();
+ if (pred_expressions->getSize() == 0) // unset predicates
+ return false;
+
+ int thread_id = id_to_int(tid);
+ bool pruned = false;
+
+ uint old_size = thrd_pruned_writes.size();
+ if (thrd_pruned_writes.size() <= (uint) thread_id) {
+ uint new_size = thread_id + 1;
+ thrd_pruned_writes.resize(new_size);
+ for (uint i = old_size; i < new_size; i++)
+ thrd_pruned_writes[i] = new SnapVector<ModelAction *>();
+ }
+ SnapVector<ModelAction *> * pruned_writes = thrd_pruned_writes[thread_id];
+ pruned_writes->clear(); // clear the old pruned_writes set
+
+ uint index = 0;
+ while ( index < rf_set->size() ) {
+ ModelAction * write_act = (*rf_set)[index];
+ bool satisfy_predicate = true;
+
+ PredExprSetIter * pred_expr_it = pred_expressions->iterator();
+ while (pred_expr_it->hasNext()) {
+ struct pred_expr * expression = pred_expr_it->next();
+ uint64_t write_val = write_act->get_write_value();
+ bool equality;
+
+ // No predicate, return everything in the rf_set
+ if (expression->token == NOPREDICATE)
+ return pruned;
+
+ switch(expression->token) {
+ case EQUALITY:
+ FuncInst * to_be_compared;
+ ModelAction * last_act;
+ uint64_t last_read;
+
+ to_be_compared = expression->func_inst;
+ last_act = inst_act_map->get(to_be_compared);
+ last_read = last_act->get_reads_from_value();
+
+ equality = (write_val == last_read);
+ if (equality != expression->value)
+ satisfy_predicate = false;
+ break;
+ case NULLITY:
+ equality = ((void*)write_val == NULL);
+ if (equality != expression->value)
+ satisfy_predicate = false;
+ break;
+ default:
+ model_print("unknown predicate token\n");
+ break;
+ }
+
+ if (!satisfy_predicate)
+ break;
+ }
+
+ if (!satisfy_predicate) {
+ ASSERT(rf_set != NULL);
+ (*rf_set)[index] = rf_set->back();
+ rf_set->pop_back();
+ pruned_writes->push_back(write_act);
+ pruned = true;
+ } else
+ index++;
+ }
+
+ return pruned;
+}