inst_list(),
entry_insts(),
// thrd_read_map(),
- action_list_buffer()
+ action_list_buffer(),
+ predicate_tree_position()
{
predicate_tree_entry = new Predicate(NULL, true);
predicate_tree_entry->add_predicate_expr(NOPREDICATE, NULL, true);
- // memory will be reclaimed after each execution
+ // memories that are reclaimed after each execution
read_locations = new loc_set_t();
val_loc_map = new HashTable<uint64_t, loc_set_t *, uint64_t, 0>();
loc_may_equal_map = new HashTable<void *, loc_set_t *, uintptr_t, 0>();
- values_may_read_from = new value_set_t();
+ //values_may_read_from = new value_set_t();
}
-/* Reallocate some snapshotted memories when new executions start */
+/* Reallocate snapshotted memories when new executions start */
void FuncNode::set_new_exec_flag()
{
// for (uint i = 0; i < thrd_read_map.size(); i++)
for (mllnode<FuncInst *> * it = inst_list.begin(); it != NULL; it = it->getNext()) {
FuncInst * inst = it->getVal();
- inst->reset_location();
+ inst->unset_location();
}
read_locations = new loc_set_t();
val_loc_map = new HashTable<uint64_t, loc_set_t *, uint64_t, 0>();
loc_may_equal_map = new HashTable<void *, loc_set_t *, uintptr_t, 0>();
- values_may_read_from = new value_set_t();
+ //values_may_read_from = new value_set_t();
}
/* Check whether FuncInst with the same type, position, and location
}
}
- model_print("function %s\n", func_name);
+// model_print("function %s\n", func_name);
// print_val_loc_map();
update_inst_tree(&inst_list);
update_predicate_tree(&read_act_list);
- print_predicate_tree();
+// print_predicate_tree();
}
/**
/* @param tid thread id
* Store the values read by atomic read actions into thrd_read_map */
-void FuncNode::store_read(ModelAction * act, uint32_t tid)
+void FuncNode::store_read(ModelAction * act, thread_id_t tid)
{
/*
ASSERT(act);
*/
}
-uint64_t FuncNode::query_last_read(void * location, uint32_t tid)
+uint64_t FuncNode::query_last_read(void * location, thread_id_t tid)
{
/*
if (thrd_read_map.size() <= tid)
* Reset read map for a thread. This function shall only be called
* when a thread exits a function
*/
-void FuncNode::clear_read_map(uint32_t tid)
+void FuncNode::clear_read_map(thread_id_t tid)
{
/*
if (thrd_read_map.size() <= tid)
while (it != NULL) {
ModelAction * next_act = it->getVal();
FuncInst * next_inst = get_inst(next_act);
- SnapVector<Predicate *> * unset_predicates = new SnapVector<Predicate *>();
- bool branch_found = follow_branch(&curr_pred, next_inst, next_act, &inst_act_map, unset_predicates);
+ SnapVector<Predicate *> unset_predicates = SnapVector<Predicate *>();
+ bool branch_found = follow_branch(&curr_pred, next_inst, next_act, &inst_act_map, &unset_predicates);
- // no predicate expressions, follow the only branch
- if (!branch_found && unset_predicates->size() != 0) {
- ASSERT(unset_predicates->size() == 1);
- Predicate * one_branch = (*unset_predicates)[0];
- curr_pred = one_branch;
- branch_found = true;
- }
+ // no predicate expressions
+ if (!branch_found && unset_predicates.size() != 0) {
+ ASSERT(unset_predicates.size() == 1);
+ Predicate * one_branch = unset_predicates[0];
- delete unset_predicates;
+ bool amended = amend_predicate_expr(&curr_pred, next_inst, next_act);
+ if (amended)
+ continue;
+ else {
+ curr_pred = one_branch;
+ branch_found = true;
+ }
+ }
// detect loops
if (!branch_found && inst_id_map.contains(next_inst)) {
if (loc_act_map.contains(neighbor)) {
ModelAction * last_act = loc_act_map.get(neighbor);
FuncInst * last_inst = get_inst(last_act);
+
struct half_pred_expr * expression = new half_pred_expr(EQUALITY, last_inst);
half_pred_expressions.push_back(expression);
}
}
} else {
// next_inst is not single location
- struct half_pred_expr * expression = new half_pred_expr(NULLITY, NULL);
- half_pred_expressions.push_back(expression);
+ uint64_t read_val = next_act->get_reads_from_value();
+
+ // only generate NULLITY predicate when it is actually NULL.
+ if ( (void*)read_val == NULL) {
+ struct half_pred_expr * expression = new half_pred_expr(NULLITY, NULL);
+ half_pred_expressions.push_back(expression);
+ }
}
if (half_pred_expressions.size() == 0) {
}
}
+/* Amend predicates that contain no predicate expressions. Currenlty only amend with NULLITY predicates */
+bool FuncNode::amend_predicate_expr(Predicate ** curr_pred, FuncInst * next_inst, ModelAction * next_act)
+{
+ // there should only be only child
+ Predicate * unset_pred = (*curr_pred)->get_children()->back();
+ uint64_t read_val = next_act->get_reads_from_value();
+
+ // only generate NULLITY predicate when it is actually NULL.
+ if ( !next_inst->is_single_location() && (void*)read_val == NULL ) {
+ Predicate * new_pred = new Predicate(next_inst);
+
+ (*curr_pred)->add_child(new_pred);
+ new_pred->set_parent(*curr_pred);
+
+ unset_pred->add_predicate_expr(NULLITY, NULL, false);
+ new_pred->add_predicate_expr(NULLITY, NULL, true);
+
+ return true;
+ }
+
+ return false;
+}
void FuncNode::add_to_val_loc_map(uint64_t val, void * loc)
{
update_loc_may_equal_map(loc, locations);
locations->add(loc);
- values_may_read_from->add(val);
+ // values_may_read_from->add(val);
}
void FuncNode::add_to_val_loc_map(value_set_t * values, void * loc)
{
+ if (values == NULL)
+ return;
+
value_set_iter * it = values->iterator();
while (it->hasNext()) {
uint64_t val = it->next();
}
}
+void FuncNode::init_predicate_tree_position(thread_id_t tid)
+{
+ uint thread_id = id_to_int(tid);
+ if (predicate_tree_position.size() <= thread_id)
+ predicate_tree_position.resize(thread_id + 1);
+
+ predicate_tree_position[thread_id] = predicate_tree_entry;
+}
+
+void FuncNode::unset_predicate_tree_position(thread_id_t tid)
+{
+ uint thread_id = id_to_int(tid);
+ predicate_tree_position[thread_id] = NULL;
+}
+
+Predicate * FuncNode::get_predicate_tree_position(thread_id_t tid)
+{
+ uint thread_id = id_to_int(tid);
+ return predicate_tree_position[thread_id];
+}
+
void FuncNode::print_predicate_tree()
{
model_print("digraph function_%s {\n", func_name);
void FuncNode::print_val_loc_map()
{
+/*
value_set_iter * val_it = values_may_read_from->iterator();
while (val_it->hasNext()) {
uint64_t value = val_it->next();
}
model_print("\n");
}
+*/
}
/* @param tid thread id
* Print the values read by the last read actions for each memory location
*/
/*
-void FuncNode::print_last_read(uint32_t tid)
+void FuncNode::print_last_read(thread_id_t tid)
{
ASSERT(thrd_read_map.size() > tid);
read_map_t * read_map = thrd_read_map[tid];