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