X-Git-Url: http://plrg.eecs.uci.edu/git/?p=c11tester.git;a=blobdiff_plain;f=history.cc;h=deaab0be37bae9818dd053db4055bb0de5ba0bfd;hp=fc71b9f2136d5815e2a2fdedfeec721ba31143bf;hb=755d1463d1871b4d075b59b5c9e17c409e12db9a;hpb=8e495e50d0a239f43fd000164e21da7964e51e54 diff --git a/history.cc b/history.cc index fc71b9f2..deaab0be 100644 --- a/history.cc +++ b/history.cc @@ -10,61 +10,66 @@ /** @brief Constructor */ ModelHistory::ModelHistory() : - func_counter(1), /* function id starts with 1 */ + func_counter(1), /* function id starts with 1 */ func_map(), func_map_rev(), - func_nodes() + func_nodes(), + write_history(), + write_locations() {} void ModelHistory::enter_function(const uint32_t func_id, thread_id_t tid) { //model_print("thread %d entering func %d\n", tid, func_id); uint32_t id = id_to_int(tid); - SnapVector * thrd_func_list = model->get_execution()->get_thrd_func_list(); + SnapVector * thrd_func_list = model->get_execution()->get_thrd_func_list(); SnapVector< SnapList *> * - thrd_func_inst_lists = model->get_execution()->get_thrd_func_inst_lists(); + thrd_func_inst_lists = model->get_execution()->get_thrd_func_inst_lists(); if ( thrd_func_list->size() <= id ) { + uint oldsize = thrd_func_list->size(); thrd_func_list->resize( id + 1 ); + for (uint i = oldsize; i < id + 1; i++) { + // push 0 as a dummy function id to a void seg fault + (*thrd_func_list)[i].push_back(0); + } + thrd_func_inst_lists->resize( id + 1 ); } - func_id_list_t * func_list = thrd_func_list->at(id); SnapList * func_inst_lists = thrd_func_inst_lists->at(id); - if (func_list == NULL) { - func_list = new func_id_list_t(); - thrd_func_list->at(id) = func_list; - } - if (func_inst_lists == NULL) { func_inst_lists = new SnapList< func_inst_list_t *>(); thrd_func_inst_lists->at(id) = func_inst_lists; } - func_list->push_back(func_id); + (*thrd_func_list)[id].push_back(func_id); func_inst_lists->push_back( new func_inst_list_t() ); + + if ( func_nodes.size() <= func_id ) + resize_func_nodes( func_id + 1 ); } /* @param func_id a non-zero value */ void ModelHistory::exit_function(const uint32_t func_id, thread_id_t tid) { uint32_t id = id_to_int(tid); - SnapVector * thrd_func_list = model->get_execution()->get_thrd_func_list(); + SnapVector * thrd_func_list = model->get_execution()->get_thrd_func_list(); SnapVector< SnapList *> * - thrd_func_inst_lists = model->get_execution()->get_thrd_func_inst_lists(); + thrd_func_inst_lists = model->get_execution()->get_thrd_func_inst_lists(); - func_id_list_t * func_list = thrd_func_list->at(id); SnapList * func_inst_lists = thrd_func_inst_lists->at(id); - - uint32_t last_func_id = func_list->back(); + uint32_t last_func_id = (*thrd_func_list)[id].back(); if (last_func_id == func_id) { - func_list->pop_back(); + FuncNode * func_node = func_nodes[func_id]; + func_node->clear_read_map(tid); func_inst_list_t * curr_inst_list = func_inst_lists->back(); - link_insts(curr_inst_list); + func_node->link_insts(curr_inst_list); + (*thrd_func_list)[id].pop_back(); func_inst_lists->pop_back(); } else { model_print("trying to exit with a wrong function id\n"); @@ -73,106 +78,130 @@ void ModelHistory::exit_function(const uint32_t func_id, thread_id_t tid) //model_print("thread %d exiting func %d\n", tid, func_id); } +void ModelHistory::resize_func_nodes(uint32_t new_size) +{ + uint32_t old_size = func_nodes.size(); + + if ( old_size < new_size ) + func_nodes.resize(new_size); + + for (uint32_t id = old_size;id < new_size;id++) { + const char * func_name = func_map_rev[id]; + FuncNode * func_node = new FuncNode(); + func_node->set_func_id(id); + func_node->set_func_name(func_name); + func_nodes[id] = func_node; + } +} + void ModelHistory::process_action(ModelAction *act, thread_id_t tid) { /* return if thread i has not entered any function or has exited from all functions */ - SnapVector * thrd_func_list = model->get_execution()->get_thrd_func_list(); + SnapVector * thrd_func_list = model->get_execution()->get_thrd_func_list(); SnapVector< SnapList *> * - thrd_func_inst_lists = model->get_execution()->get_thrd_func_inst_lists(); + thrd_func_inst_lists = model->get_execution()->get_thrd_func_inst_lists(); uint32_t id = id_to_int(tid); if ( thrd_func_list->size() <= id ) return; - else if (thrd_func_list->at(id) == NULL) - return; /* get the function id that thread i is currently in */ - func_id_list_t * func_list = thrd_func_list->at(id); + uint32_t func_id = (*thrd_func_list)[id].back(); SnapList * func_inst_lists = thrd_func_inst_lists->at(id); - uint32_t func_id = func_list->back(); - - if ( func_nodes.size() <= func_id ) - func_nodes.resize( func_id + 1 ); + if (func_id == 0) + return; + else if ( func_nodes.size() <= func_id ) + resize_func_nodes( func_id + 1 ); FuncNode * func_node = func_nodes[func_id]; - if (func_node == NULL) { - const char * func_name = func_map_rev[func_id]; - func_node = new FuncNode(); - func_node->set_func_id(func_id); - func_node->set_func_name(func_name); + ASSERT (func_node != NULL); - func_nodes[func_id] = func_node; - } - - /* add corresponding FuncInst to func_node and curr_inst_list*/ + /* add corresponding FuncInst to func_node */ FuncInst * inst = func_node->get_or_add_action(act); - if (inst != NULL) { - func_inst_list_t * curr_inst_list = func_inst_lists->back(); - ASSERT(curr_inst_list != NULL); - curr_inst_list->push_back(inst); - } + if (inst == NULL) + return; + + if (inst->is_read()) + func_node->store_read(act, tid); + + if (inst->is_write()) + add_to_write_history(act->get_location(), act->get_write_value()); + + /* add to curr_inst_list */ + func_inst_list_t * curr_inst_list = func_inst_lists->back(); + ASSERT(curr_inst_list != NULL); + curr_inst_list->push_back(inst); } -/* Link FuncInsts in a list - add one FuncInst to another's predecessors and successors */ -void ModelHistory::link_insts(func_inst_list_t * inst_list) +/* return the FuncNode given its func_id */ +FuncNode * ModelHistory::get_func_node(uint32_t func_id) { - if (inst_list == NULL) - return; + if (func_nodes.size() <= func_id) // this node has not been added + return NULL; - func_inst_list_t::iterator it = inst_list->begin(); - func_inst_list_t::iterator prev; + return func_nodes[func_id]; +} - if (inst_list->size() == 0) - return; +uint64_t ModelHistory::query_last_read(void * location, thread_id_t tid) +{ + SnapVector * thrd_func_list = model->get_execution()->get_thrd_func_list(); + uint32_t id = id_to_int(tid); - /* add the first instruction to the list of entry insts */ - FuncInst * entry_inst = *it; - FuncNode * func_node = entry_inst->get_func_node(); - func_node->add_entry_inst(entry_inst); + ASSERT( thrd_func_list->size() > id ); + uint32_t func_id = (*thrd_func_list)[id].back(); + FuncNode * func_node = func_nodes[func_id]; - it++; - while (it != inst_list->end()) { - prev = it; - prev--; + uint64_t last_read_val = 0xdeadbeef; + if (func_node != NULL) { + last_read_val = func_node->query_last_read(location, tid); + } - FuncInst * prev_inst = *prev; - FuncInst * curr_inst = *it; + return last_read_val; +} - prev_inst->add_succ(curr_inst); - curr_inst->add_pred(prev_inst); +void ModelHistory::add_to_write_history(void * location, uint64_t write_val) +{ + write_set_t * write_set = write_history.get(location); - it++; + if (write_set == NULL) { + write_set = new write_set_t(); + write_history.put(location, write_set); } + + write_set->add(write_val); + write_locations.add(location); } -void ModelHistory::print() +void ModelHistory::print_write() { - for (uint32_t i = 0; i < func_nodes.size(); i++ ) { - FuncNode * funcNode = func_nodes[i]; - if (funcNode == NULL) - continue; - - func_inst_list_mt * entry_insts = funcNode->get_entry_insts(); +} - model_print("function %s has entry actions\n", funcNode->get_func_name()); - func_inst_list_mt::iterator it; - for (it = entry_insts->begin(); it != entry_insts->end(); it++) { - FuncInst *inst = *it; - model_print("type: %d, at: %s\n", inst->get_type(), inst->get_position()); - } +void ModelHistory::print_func_node() +{ + /* function id starts with 1 */ + for (uint32_t i = 1; i < func_nodes.size(); i++) { + FuncNode * func_node = func_nodes[i]; -/* - func_inst_list_mt * inst_list = funcNode->get_inst_list(); + func_inst_list_mt * entry_insts = func_node->get_entry_insts(); + model_print("function %s has entry actions\n", func_node->get_func_name()); - model_print("function %s has following actions\n", funcNode->get_func_name()); - func_inst_list_mt::iterator it; - for (it = inst_list->begin(); it != inst_list->end(); it++) { - FuncInst *inst = *it; + mllnode* it; + for (it = entry_insts->begin();it != NULL;it=it->getNext()) { + FuncInst *inst = it->getVal(); model_print("type: %d, at: %s\n", inst->get_type(), inst->get_position()); } +/* + func_inst_list_mt * inst_list = funcNode->get_inst_list(); + + model_print("function %s has following actions\n", funcNode->get_func_name()); + func_inst_list_mt::iterator it; + for (it = inst_list->begin(); it != inst_list->end(); it++) { + FuncInst *inst = *it; + model_print("type: %d, at: %s\n", inst->get_type(), inst->get_position()); + } */ } }