Keep track of which FuncNodes may write to a memory location
[c11tester.git] / funcinst.h
1 #ifndef __FUNCINST_H__
2 #define __FUNCINST_H__
3
4 #include "action.h"
5 #include "hashtable.h"
6
7 class ModelAction;
8
9 typedef ModelList<FuncInst *> func_inst_list_mt;
10
11 class FuncInst {
12 public:
13         FuncInst(ModelAction *act, FuncNode *func_node);
14         ~FuncInst();
15
16         const char * get_position() const { return position; }
17
18         void * get_location() const { return location; }
19         void set_location(void * loc) { location = loc; }
20         void unset_location() { location = NULL; }
21
22         action_type get_type() const { return type; }
23         memory_order get_mo() const { return order; }
24         FuncNode * get_func_node() const { return func_node; }
25
26         bool add_pred(FuncInst * other);
27         bool add_succ(FuncInst * other);
28
29         //FuncInst * search_in_collision(ModelAction *act);
30         //func_inst_list_mt * get_collisions() { return &collisions; }
31
32         func_inst_list_mt * get_preds() { return &predecessors; }
33         func_inst_list_mt * get_succs() { return &successors; }
34
35         bool is_read() const;
36         bool is_write() const;
37         bool is_single_location() { return single_location; }
38         void not_single_location() { single_location = false; }
39
40         void print();
41
42         MEMALLOC
43 private:
44         const char * position;
45
46         /* Atomic operations with the same source line number may act at different
47          * memory locations, such as the next field of the head pointer in ms-queue. 
48          * location only stores the memory location when this FuncInst was constructed.
49          */
50         void * location;
51
52         /* NOTE: for rmw actions, func_inst and act may have different
53          * action types because of action type conversion in ModelExecution */
54         action_type type;
55
56         memory_order order;
57         FuncNode * func_node;
58
59         bool single_location;
60
61         /* Currently not in use. May remove this field later
62          *
63          * collisions store a list of FuncInsts with the same position
64          * but different action types. For example, CAS is broken down
65          * as three different atomic operations in cmodelint.cc */
66         // func_inst_list_mt collisions;
67
68         func_inst_list_mt predecessors;
69         func_inst_list_mt successors;
70 };
71
72 #endif  /* __FUNCINST_H__ */