Design a method to select predicate branches based on exploration counts
[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);
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 add_backedge(Predicate * back_pred) { backedges.add(back_pred); }
25         void copy_predicate_expr(Predicate * other);
26
27         ModelVector<Predicate *> * get_children() { return &children; }
28         Predicate * get_parent() { return parent; }
29         PredSet * get_backedges() { return &backedges; }
30
31         bool is_entry_predicate() { return entry_predicate; }
32         void set_entry_predicate() { entry_predicate = true; }
33
34         /* Whether func_inst does write or not */
35         bool is_write() { return does_write; }
36         void set_write(bool is_write) { does_write = is_write; }
37
38         ConcretePredicate * evaluate(inst_act_map_t * inst_act_map, thread_id_t tid);
39
40         uint32_t get_count() { return exploration_count; }
41         void incr_count() { exploration_count++; }
42
43         void print_predicate();
44         void print_pred_subtree();
45
46         MEMALLOC
47 private:
48         FuncInst * func_inst;
49         bool entry_predicate;
50         bool does_write;
51         uint32_t exploration_count;
52
53         /* May have multiple predicate expressions */
54         PredExprSet pred_expressions;
55         ModelVector<Predicate *> children;
56
57         /* Only a single parent may exist */
58         Predicate * parent;
59
60         /* May have multiple back edges, e.g. nested loops */
61         PredSet backedges;
62 };
63
64 #endif /* __PREDICATE_H__ */