Remove redundant data structures and FuncNode's dependencies on old actions
[c11tester.git] / funcinst.cc
1 #include "funcinst.h"
2 #include "model.h"
3
4 FuncInst::FuncInst(ModelAction *act, FuncNode *func_node) :
5         single_location(true),
6         execution_number(0),
7         associated_reads(),
8         thrd_marker()   /* The marker for FuncNode starts from 1 */
9 {
10         ASSERT(act);
11         ASSERT(func_node);
12         this->position = act->get_position();
13         this->location = act->get_location();
14         this->type = act->get_type();
15         this->order = act->get_mo();
16         this->func_node = func_node;
17 }
18
19 /* @param other Preceding FuncInst in the same execution trace
20  * Add other to predecessors if it has been added
21  *
22  * @return false: other is already in predecessors
23  *         true : other is added to precedessors
24  */
25 bool FuncInst::add_pred(FuncInst * other)
26 {
27         mllnode<FuncInst*> * it;
28         for (it = predecessors.begin();it != NULL;it=it->getNext()) {
29                 FuncInst * inst = it->getVal();
30                 if (inst == other)
31                         return false;
32         }
33
34         predecessors.push_back(other);
35         return true;
36 }
37
38 bool FuncInst::add_succ(FuncInst * other)
39 {
40         mllnode<FuncInst*>* it;
41         for (it = successors.begin();it != NULL;it=it->getNext()) {
42                 FuncInst * inst = it->getVal();
43                 if ( inst == other )
44                         return false;
45         }
46
47         successors.push_back(other);
48         return true;
49 }
50
51 void FuncInst::set_associated_read(thread_id_t tid, uint64_t read_val, uint32_t marker)
52 {
53         int thread_id = id_to_int(tid);
54         int old_size = associated_reads.size();
55
56         if (old_size < thread_id + 1) {
57                 for (int i = old_size; i < thread_id + 1; i++ ) {
58                         associated_reads.push_back(VALUE_NONE);
59                         thrd_marker.push_back(0);
60                 }
61         }
62
63         thrd_marker[thread_id] = marker;
64         associated_reads[thread_id] = read_val;
65 }
66
67 uint64_t FuncInst::get_associated_read(thread_id_t tid, uint32_t marker)
68 {
69         int thread_id = id_to_int(tid);
70
71         if (thrd_marker[thread_id] == marker)
72                 return associated_reads[thread_id];
73         else
74                 return VALUE_NONE;
75 }
76
77 /* Search the FuncInst that has the same type as act in the collision list */
78 FuncInst * FuncInst::search_in_collision(ModelAction *act)
79 {
80         action_type type = act->get_type();
81
82         mllnode<FuncInst*> * it;
83         for (it = collisions.begin();it != NULL;it = it->getNext()) {
84                 FuncInst * inst = it->getVal();
85                 if (inst->get_type() == type)
86                         return inst;
87         }
88         return NULL;
89 }
90
91 void FuncInst::add_to_collision(FuncInst * inst)
92 {
93         collisions.push_back(inst);
94 }
95
96 /* Note: is_read() is equivalent to ModelAction::is_read() */
97 bool FuncInst::is_read() const
98 {
99         return type == ATOMIC_READ || type == ATOMIC_RMWR || type == ATOMIC_RMWRCAS || type == ATOMIC_RMW;
100 }
101
102 /* Note: because of action type conversion in ModelExecution
103  * is_write() <==> pure writes (excluding rmw) */
104 bool FuncInst::is_write() const
105 {
106         return type == ATOMIC_WRITE || type == ATOMIC_RMW || type == ATOMIC_INIT || type == NONATOMIC_WRITE;
107 }
108
109 void FuncInst::print()
110 {
111         model_print("func inst - pos: %s, loc: %p, type: %d,\n", position, location, type);
112 }