Fix NewFuzzer::selectWrite - check back edges
[c11tester.git] / predicate.h
1 #ifndef __PREDICATE_H__
2 #define __PREDICATE_H__
3
4 #include "hashset.h"
5 #include "predicatetypes.h"
6 #include "classlist.h"
7
8 unsigned int pred_expr_hash (struct pred_expr *);
9 bool pred_expr_equal(struct pred_expr *, struct pred_expr *);
10 typedef HashSet<struct pred_expr *, uintptr_t, 0, model_malloc, model_calloc, model_free, pred_expr_hash, pred_expr_equal> PredExprSet;
11 typedef HSIterator<struct pred_expr *, uintptr_t, 0, model_malloc, model_calloc, model_free, pred_expr_hash, pred_expr_equal> PredExprSetIter;
12
13 class Predicate {
14 public:
15         Predicate(FuncInst * func_inst, bool is_entry = false, bool is_exit = false);
16         ~Predicate();
17
18         FuncInst * get_func_inst() { return func_inst; }
19         PredExprSet * get_pred_expressions() { return &pred_expressions; }
20
21         void add_predicate_expr(token_t token, FuncInst * func_inst, bool value);
22         void add_child(Predicate * child);
23         void set_parent(Predicate * parent_pred) { parent = parent_pred; }
24         void set_exit(Predicate * exit_pred) { exit = exit_pred; }
25         void add_backedge(Predicate * back_pred) { backedges.add(back_pred); }
26         void copy_predicate_expr(Predicate * other);
27
28         Predicate * get_single_child(FuncInst * inst);
29         ModelVector<Predicate *> * get_children() { return &children; }
30         Predicate * get_parent() { return parent; }
31         Predicate * get_exit() { return exit; }
32         PredSet * get_backedges() { return &backedges; }
33
34         bool is_entry_predicate() { return entry_predicate; }
35         void set_entry_predicate() { entry_predicate = true; }
36
37         /* Whether func_inst does write or not */
38         bool is_write() { return does_write; }
39         void set_write(bool is_write) { does_write = is_write; }
40
41         ConcretePredicate * evaluate(inst_act_map_t * inst_act_map, thread_id_t tid);
42
43         uint32_t get_expl_count() { return exploration_count; }
44         uint32_t get_store_visible_count() { return store_visible_count; }
45         uint32_t get_total_checking_count() { return total_checking_count; }
46
47         void incr_expl_count() { exploration_count++; }
48         void incr_store_visible_count() { store_visible_count++; }
49         void incr_total_checking_count() { total_checking_count++; }
50
51         void print_predicate();
52         void print_pred_subtree();
53
54         MEMALLOC
55 private:
56         FuncInst * func_inst;
57         bool entry_predicate;
58         bool exit_predicate;
59         bool does_write;
60
61         uint32_t exploration_count;
62         uint32_t store_visible_count;
63         uint32_t total_checking_count;  /* The number of times the store visibility is checked */
64
65         /* May have multiple predicate expressions */
66         PredExprSet pred_expressions;
67         ModelVector<Predicate *> children;
68
69         /* Only a single parent may exist */
70         Predicate * parent;
71         Predicate * exit;
72
73         /* May have multiple back edges, e.g. nested loops */
74         PredSet backedges;
75 };
76
77 #endif  /* __PREDICATE_H__ */