11 /* Check whether FuncInst with the same type, position, and location
12 * as act has been added to func_inst_map or not. If so, return it;
13 * if not, add it and return it.
15 * @return FuncInst with the same type, position, and location as act */
16 FuncInst * FuncNode::get_or_add_action(ModelAction *act)
19 const char * position = act->get_position();
21 /* Actions THREAD_CREATE, THREAD_START, THREAD_YIELD, THREAD_JOIN,
22 * THREAD_FINISH, PTHREAD_CREATE, PTHREAD_JOIN,
23 * ATOMIC_LOCK, ATOMIC_TRYLOCK, and ATOMIC_UNLOCK are not tagged with their
29 if ( func_inst_map.contains(position) ) {
30 FuncInst * inst = func_inst_map.get(position);
32 if (inst->get_type() != act->get_type() ) {
33 // model_print("action with a different type occurs at line number %s\n", position);
34 FuncInst * func_inst = inst->search_in_collision(act);
36 if (func_inst != NULL) {
37 // return the FuncInst found in the collision list
41 func_inst = new FuncInst(act, this);
42 inst->get_collisions()->push_back(func_inst);
43 inst_list.push_back(func_inst); // delete?
51 FuncInst * func_inst = new FuncInst(act, this);
53 func_inst_map.put(position, func_inst);
54 inst_list.push_back(func_inst);
59 void FuncNode::add_entry_inst(FuncInst * inst)
64 func_inst_list_mt::iterator it;
65 for (it = entry_insts.begin();it != entry_insts.end();it++) {
70 entry_insts.push_back(inst);
73 /* @param inst_list a list of FuncInsts; this argument comes from ModelExecution
74 * Link FuncInsts in a list - add one FuncInst to another's predecessors and successors
76 void FuncNode::link_insts(func_inst_list_t * inst_list)
78 if (inst_list == NULL)
81 func_inst_list_t::iterator it = inst_list->begin();
82 func_inst_list_t::iterator prev;
84 if (inst_list->size() == 0)
87 /* add the first instruction to the list of entry insts */
88 FuncInst * entry_inst = *it;
89 add_entry_inst(entry_inst);
92 while (it != inst_list->end()) {
96 FuncInst * prev_inst = *prev;
97 FuncInst * curr_inst = *it;
99 prev_inst->add_succ(curr_inst);
100 curr_inst->add_pred(prev_inst);
106 /* @param tid thread id
107 * Store the values read by atomic read actions into thrd_read_map */
108 void FuncNode::store_read(ModelAction * act, uint32_t tid)
112 void * location = act->get_location();
113 uint64_t read_from_val = act->get_reads_from_value();
115 /* resize and initialize */
116 uint32_t old_size = thrd_read_map.size();
117 if (old_size <= tid) {
118 thrd_read_map.resize(tid + 1);
119 for (uint32_t i = old_size; i < tid + 1; i++)
120 thrd_read_map[i] = new read_map_t();
123 read_map_t * read_map = thrd_read_map[tid];
124 read_map->put(location, read_from_val);
126 /* Store the memory locations where atomic reads happen */
127 // read_locations.add(location);
130 uint64_t FuncNode::query_last_read(void * location, uint32_t tid)
132 if (thrd_read_map.size() <= tid)
135 read_map_t * read_map = thrd_read_map[tid];
137 /* last read value not found */
138 if ( !read_map->contains(location) )
141 uint64_t read_val = read_map->get(location);
145 /* @param tid thread id
146 * Reset read map for a thread. This function shall only be called
147 * when a thread exits a function
149 void FuncNode::clear_read_map(uint32_t tid)
151 if (thrd_read_map.size() <= tid)
154 thrd_read_map[tid]->reset();
157 void FuncNode::generate_predicate(FuncInst *func_inst)
162 /* @param tid thread id
163 * Print the values read by the last read actions for each memory location
165 void FuncNode::print_last_read(uint32_t tid)
167 ASSERT(thrd_read_map.size() > tid);
168 read_map_t * read_map = thrd_read_map[tid];
170 ModelList<void *>::iterator it;
171 for (it = read_locations.begin();it != read_locations.end();it++) {
172 if ( !read_map->contains(*it) )
175 uint64_t read_val = read_map->get(*it);
176 model_print("last read of thread %d at %p: 0x%x\n", tid, *it, read_val);