3 #include "concretepredicate.h"
5 Predicate::Predicate(FuncInst * func_inst, bool is_entry, bool is_exit) :
7 entry_predicate(is_entry),
8 exit_predicate(is_exit),
13 store_visible_count(0),
14 total_checking_count(0),
22 Predicate::~Predicate()
24 // parent and func_inst should not be deleted
25 pred_expressions.reset();
30 unsigned int pred_expr_hash(struct pred_expr * expr)
32 return (unsigned int)((uintptr_t)expr);
35 bool pred_expr_equal(struct pred_expr * p1, struct pred_expr * p2)
37 if (p1->token != p2->token)
39 if (p1->token == EQUALITY && p1->func_inst != p2->func_inst)
41 if (p1->value != p2->value)
46 void Predicate::add_predicate_expr(token_t token, FuncInst * func_inst, bool value)
48 struct pred_expr *ptr = new pred_expr(token, func_inst, value);
49 pred_expressions.add(ptr);
52 void Predicate::add_child(Predicate * child)
54 /* check duplication? */
55 children.push_back(child);
58 void Predicate::set_parent(Predicate * parent_pred)
61 depth = parent_pred->get_depth() + 1;
64 void Predicate::set_exit(Predicate * exit_pred)
69 void Predicate::copy_predicate_expr(Predicate * other)
71 PredExprSet * other_pred_expressions = other->get_pred_expressions();
72 PredExprSetIter * it = other_pred_expressions->iterator();
74 while (it->hasNext()) {
75 struct pred_expr * ptr = it->next();
76 struct pred_expr * copy = new pred_expr(ptr->token, ptr->func_inst, ptr->value);
77 pred_expressions.add(copy);
83 /* Follow the child if any child whose FuncInst matches with inst
85 * @param inst must be an ATOMIC_WRITE FuncInst
86 * @return NULL if no such child is found.
88 Predicate * Predicate::follow_write_child(FuncInst * inst)
90 ASSERT(inst->get_type() == ATOMIC_WRITE);
92 for (uint i = 0;i < children.size();i++) {
93 Predicate * child = children[i];
94 if (child->get_func_inst() == inst)
101 /* Evaluate predicate expressions against the given inst_act_map */
102 ConcretePredicate * Predicate::evaluate(inst_act_map_t * inst_act_map, thread_id_t tid)
104 ConcretePredicate * concrete = new ConcretePredicate(tid);
105 PredExprSetIter * it = pred_expressions.iterator();
107 while (it->hasNext()) {
108 struct pred_expr * ptr = it->next();
115 FuncInst * to_be_compared;
116 ModelAction * last_act;
118 to_be_compared = ptr->func_inst;
119 last_act = inst_act_map->get(to_be_compared);
120 value = last_act->get_reads_from_value();
128 concrete->add_expression(ptr->token, value, ptr->value);
135 void Predicate::print_predicate()
137 model_print("\"%p\" [shape=box, label=\"", this);
138 if (entry_predicate) {
139 model_print("entry node\"];\n");
143 if (exit_predicate) {
144 model_print("exit node\"];\n");
148 model_print("depth: %u; weight: %g\n", depth, weight);
152 if (pred_expressions.getSize() == 0)
153 model_print("predicate unset\n");
155 PredExprSetIter * it = pred_expressions.iterator();
156 while (it->hasNext()) {
157 struct pred_expr * expr = it->next();
158 FuncInst * inst = expr->func_inst;
159 switch (expr->token) {
163 model_print("predicate token: equality, position: %s, value: %d\n", inst->get_position(), expr->value);
166 model_print("predicate token: nullity, value: %d\n", expr->value);
169 model_print("unknown predicate token\n");
175 model_print("Does write\n");
178 double prob = (double) store_visible_count / total_checking_count;
179 model_print("Total checks: %d, visible count: %d; prob: %f\n", total_checking_count, store_visible_count, prob);
180 model_print("Exploration count: %d, failure count: %d", exploration_count, failure_count);
181 model_print("\"];\n");
186 void Predicate::print_pred_subtree()
189 for (uint i = 0;i < children.size();i++) {
190 Predicate * child = children[i];
191 child->print_pred_subtree();
192 model_print("\"%p\" -> \"%p\"\n", this, child);
195 PredSetIter * it = backedges.iterator();
196 while (it->hasNext()) {
197 Predicate * backedge = it->next();
198 model_print("\"%p\" -> \"%p\"[style=dashed, color=grey]\n", this, backedge);
202 model_print("\"%p\" -> \"%p\"[style=dashed, color=red]\n", this, exit);