Complete the transfer of deletions of some actions
[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);
27         void add_backedge(Predicate * back_pred) { backedges.add(back_pred); }
28         void set_weight(double weight_) { weight = weight_; }
29         void copy_predicate_expr(Predicate * other);
30
31         Predicate * follow_write_child(FuncInst * inst);
32         ModelVector<Predicate *> * get_children() { return &children; }
33         Predicate * get_parent() { return parent; }
34         Predicate * get_exit() { return exit; }
35         PredSet * get_backedges() { return &backedges; }
36         double get_weight() { return weight; }
37
38         bool is_entry_predicate() { return entry_predicate; }
39         void set_entry_predicate() { entry_predicate = true; }
40
41         /* Whether func_inst does write or not */
42         bool is_write() { return does_write; }
43         void set_write(bool is_write) { does_write = is_write; }
44
45         ConcretePredicate * evaluate(inst_act_map_t * inst_act_map, thread_id_t tid);
46
47         uint32_t get_expl_count() { return exploration_count; }
48         uint32_t get_fail_count() { return failure_count; }
49         uint32_t get_store_visible_count() { return store_visible_count; }
50         uint32_t get_total_checking_count() { return total_checking_count; }
51
52         void incr_expl_count() { exploration_count++; }
53         void incr_fail_count() { failure_count++; }
54         void incr_store_visible_count() { store_visible_count++; }
55         void incr_total_checking_count() { total_checking_count++; }
56
57         uint32_t get_depth() { return depth; }
58         void set_depth(uint32_t depth_) { depth = depth_; }
59
60         void print_predicate();
61         void print_pred_subtree();
62
63         MEMALLOC
64 private:
65         FuncInst * func_inst;
66         bool entry_predicate;
67         bool exit_predicate;
68         bool does_write;
69
70         /* Height of this predicate node in the predicate tree */
71         uint32_t depth;
72         double weight;
73
74         uint32_t exploration_count;
75         uint32_t failure_count;
76         uint32_t store_visible_count;
77         uint32_t total_checking_count;  /* The number of times the store visibility is checked */
78
79         /* May have multiple predicate expressions */
80         PredExprSet pred_expressions;
81         ModelVector<Predicate *> children;
82
83         /* Only a single parent may exist */
84         Predicate * parent;
85         Predicate * exit;
86
87         /* May have multiple back edges, e.g. nested loops */
88         PredSet backedges;
89 };
90
91 #endif  /* __PREDICATE_H__ */