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),
12 store_visible_count(0),
13 total_checking_count(0),
21 Predicate::~Predicate()
23 // parent and func_inst should not be deleted
24 pred_expressions.reset();
29 unsigned int pred_expr_hash(struct pred_expr * expr)
31 return (unsigned int)((uintptr_t)expr);
34 bool pred_expr_equal(struct pred_expr * p1, struct pred_expr * p2)
36 if (p1->token != p2->token)
38 if (p1->token == EQUALITY && p1->func_inst != p2->func_inst)
40 if (p1->value != p2->value)
45 void Predicate::add_predicate_expr(token_t token, FuncInst * func_inst, bool value)
47 struct pred_expr *ptr = new pred_expr(token, func_inst, value);
48 pred_expressions.add(ptr);
51 void Predicate::add_child(Predicate * child)
53 /* check duplication? */
54 children.push_back(child);
57 void Predicate::set_parent(Predicate * parent_pred)
60 depth = parent_pred->get_depth() + 1;
63 void Predicate::copy_predicate_expr(Predicate * other)
65 PredExprSet * other_pred_expressions = other->get_pred_expressions();
66 PredExprSetIter * it = other_pred_expressions->iterator();
68 while (it->hasNext()) {
69 struct pred_expr * ptr = it->next();
70 struct pred_expr * copy = new pred_expr(ptr->token, ptr->func_inst, ptr->value);
71 pred_expressions.add(copy);
75 /* Return the single child branch of this predicate.
76 * Return NULL if this predicate has no children.
78 Predicate * Predicate::get_single_child(FuncInst * inst)
80 int size = children.size();
84 /* Should only have one child */
86 Predicate * child = children[0];
88 ASSERT(child->get_func_inst() == inst);
93 /* Evaluate predicate expressions against the given inst_act_map */
94 ConcretePredicate * Predicate::evaluate(inst_act_map_t * inst_act_map, thread_id_t tid)
96 ConcretePredicate * concrete = new ConcretePredicate(tid);
97 PredExprSetIter * it = pred_expressions.iterator();
99 while (it->hasNext()) {
100 struct pred_expr * ptr = it->next();
107 FuncInst * to_be_compared;
108 ModelAction * last_act;
110 to_be_compared = ptr->func_inst;
111 last_act = inst_act_map->get(to_be_compared);
112 value = last_act->get_reads_from_value();
120 concrete->add_expression(ptr->token, value, ptr->value);
126 void Predicate::print_predicate()
128 model_print("\"%p\" [shape=box, label=\"", this);
129 if (entry_predicate) {
130 model_print("entry node\"];\n");
134 if (exit_predicate) {
135 model_print("exit node\"];\n");
139 model_print("depth: %d\n", depth);
143 if (pred_expressions.getSize() == 0)
144 model_print("predicate unset\n");
146 PredExprSetIter * it = pred_expressions.iterator();
147 while (it->hasNext()) {
148 struct pred_expr * expr = it->next();
149 FuncInst * inst = expr->func_inst;
150 switch (expr->token) {
154 model_print("predicate token: equality, position: %s, value: %d\n", inst->get_position(), expr->value);
157 model_print("predicate token: nullity, value: %d\n", expr->value);
160 model_print("unknown predicate token\n");
166 model_print("Does write\n");
169 double prob = (double) store_visible_count / total_checking_count;
170 model_print("Total checks: %d, visible count: %d; prob: %f\n", total_checking_count, store_visible_count, prob);
171 model_print("Exploration count: %d", exploration_count);
172 model_print("\"];\n");
175 void Predicate::print_pred_subtree()
178 for (uint i = 0;i < children.size();i++) {
179 Predicate * child = children[i];
180 child->print_pred_subtree();
181 model_print("\"%p\" -> \"%p\"\n", this, child);
184 PredSetIter * it = backedges.iterator();
185 while (it->hasNext()) {
186 Predicate * backedge = it->next();
187 model_print("\"%p\" -> \"%p\"[style=dashed, color=grey]\n", this, backedge);
191 model_print("\"%p\" -> \"%p\"[style=dashed, color=red]\n", this, exit);