From: weiyu Date: Fri, 19 Jul 2019 23:56:43 +0000 (-0700) Subject: move the 'link_insts' method to FuncNode class X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=44870f54a17bd7a61a94465aec78144c689e336b;p=c11tester.git move the 'link_insts' method to FuncNode class --- diff --git a/funcnode.cc b/funcnode.cc index 843e1c94..6b1f1997 100644 --- a/funcnode.cc +++ b/funcnode.cc @@ -4,6 +4,7 @@ FuncNode::FuncNode() : func_inst_map(), inst_list(), entry_insts(), + thrd_read_map(), read_locations() {} @@ -69,6 +70,39 @@ void FuncNode::add_entry_inst(FuncInst * inst) entry_insts.push_back(inst); } +/* @param inst_list a list of FuncInsts; this argument comes from ModelExecution + * Link FuncInsts in a list - add one FuncInst to another's predecessors and successors + */ +void FuncNode::link_insts(func_inst_list_t * inst_list) +{ + if (inst_list == NULL) + return; + + func_inst_list_t::iterator it = inst_list->begin(); + func_inst_list_t::iterator prev; + + if (inst_list->size() == 0) + return; + + /* add the first instruction to the list of entry insts */ + FuncInst * entry_inst = *it; + add_entry_inst(entry_inst); + + it++; + while (it != inst_list->end()) { + prev = it; + prev--; + + FuncInst * prev_inst = *prev; + FuncInst * curr_inst = *it; + + prev_inst->add_succ(curr_inst); + curr_inst->add_pred(prev_inst); + + it++; + } +} + /* @param tid thread id * Store the values read by atomic read actions into thrd_read_map */ void FuncNode::store_read(ModelAction * act, uint32_t tid) diff --git a/funcnode.h b/funcnode.h index a87c0306..9df33343 100644 --- a/funcnode.h +++ b/funcnode.h @@ -23,6 +23,7 @@ public: func_inst_list_mt * get_inst_list() { return &inst_list; } func_inst_list_mt * get_entry_insts() { return &entry_insts; } void add_entry_inst(FuncInst * inst); + void link_insts(func_inst_list_t * inst_list); void store_read(ModelAction * act, uint32_t tid); uint64_t query_last_read(ModelAction * act, uint32_t tid); diff --git a/history.cc b/history.cc index d3e36c6a..ee4c90a0 100644 --- a/history.cc +++ b/history.cc @@ -62,8 +62,12 @@ void ModelHistory::exit_function(const uint32_t func_id, thread_id_t tid) if (last_func_id == func_id) { func_list->pop_back(); + /* clear read map upon exiting functions */ + 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); func_inst_lists->pop_back(); } else { @@ -106,7 +110,7 @@ void ModelHistory::process_action(ModelAction *act, thread_id_t tid) 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) @@ -115,53 +119,21 @@ void ModelHistory::process_action(ModelAction *act, thread_id_t tid) if (inst->is_read()) func_node->store_read(act, tid); + /* 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) -{ - if (inst_list == NULL) - return; - - func_inst_list_t::iterator it = inst_list->begin(); - func_inst_list_t::iterator prev; - - if (inst_list->size() == 0) - return; - - /* 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); - - it++; - while (it != inst_list->end()) { - prev = it; - prev--; - - FuncInst * prev_inst = *prev; - FuncInst * curr_inst = *it; - - prev_inst->add_succ(curr_inst); - curr_inst->add_pred(prev_inst); - - it++; - } -} - void ModelHistory::print() { - for (uint32_t i = 0; i < func_nodes.size(); i++ ) { - FuncNode * funcNode = func_nodes[i]; - if (funcNode == NULL) - continue; + /* 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 * entry_insts = funcNode->get_entry_insts(); + 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 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; diff --git a/history.h b/history.h index 0289a6d6..6da1be11 100644 --- a/history.h +++ b/history.h @@ -21,7 +21,6 @@ public: ModelVector * getFuncNodes() { return &func_nodes; } - void link_insts(func_inst_list_t * inst_list); void print(); MEMALLOC