From 06c988d6e758d2fd5d9c0a68a86c8751d8f0f8cb Mon Sep 17 00:00:00 2001 From: weiyu Date: Fri, 5 Jul 2019 17:27:16 -0700 Subject: [PATCH] add func_map_rev to map function ids to function names --- cmodelint.cc | 8 +++++++- funcnode.cc | 22 +++++++++++++++++----- funcnode.h | 31 ++++++++++++++++++++++++++++++- history.cc | 10 +++++++++- history.h | 4 ++++ 5 files changed, 67 insertions(+), 8 deletions(-) diff --git a/cmodelint.cc b/cmodelint.cc index b1a8eb43..f71c0f7e 100644 --- a/cmodelint.cc +++ b/cmodelint.cc @@ -369,10 +369,16 @@ void cds_func_entry(const char * funcName) { ModelHistory *history = model->get_history(); if ( !history->getFuncMap()->contains(funcName) ) { + /* add func id to func map */ func_id = history->get_func_counter(); history->incr_func_counter(); - history->getFuncMap()->put(funcName, func_id); + + /* add func id to reverse func map */ + ModelVector * func_map_rev = history->getFuncMapRev(); + if ( func_map_rev->size() <= func_id ) + func_map_rev->resize( func_id + 1 ); + func_map_rev->at(func_id) = funcName; } else { func_id = history->getFuncMap()->get(funcName); } diff --git a/funcnode.cc b/funcnode.cc index 27d57f06..d03b09a2 100644 --- a/funcnode.cc +++ b/funcnode.cc @@ -1,6 +1,7 @@ #include "funcnode.h" -FuncInst::FuncInst(ModelAction *act) +FuncInst::FuncInst(ModelAction *act) : + collisions() { ASSERT(act); this->position = act->get_position(); @@ -9,7 +10,9 @@ FuncInst::FuncInst(ModelAction *act) } FuncNode::FuncNode() : - func_insts() + func_insts(), + inst_list(), + entry_insts() {} void FuncNode::add_action(ModelAction *act) @@ -30,9 +33,17 @@ void FuncNode::add_action(ModelAction *act) if ( func_insts.contains(position) ) { FuncInst * inst = func_insts.get(position); - if (inst->get_type() != act->get_type() && - inst->get_type() != ATOMIC_RMWRCAS ) { - model_print("action with a different type occurs at line number %s \n", position); + if (inst->get_type() != act->get_type() ) { + model_print("action with a different type occurs at line number %s\n", position); + FuncInst * func_inst = inst->search_in_collision(act); + + if (func_inst != NULL) + return; + + func_inst = new FuncInst(act); + inst->get_collisions()->push_back(func_inst); + inst_list.push_back(func_inst); // delete? + model_print("collision added\n"); } return; @@ -40,5 +51,6 @@ void FuncNode::add_action(ModelAction *act) FuncInst * func_inst = new FuncInst(act); func_insts.put(position, func_inst); + inst_list.push_back(func_inst); } diff --git a/funcnode.h b/funcnode.h index 6ddcbb26..25e22083 100644 --- a/funcnode.h +++ b/funcnode.h @@ -15,12 +15,28 @@ public: void * get_location() const { return location; } action_type get_type() const { return type; } + func_inst_list_t * get_collisions() { return &collisions; } + + FuncInst * search_in_collision(ModelAction *act) { + action_type type = act->get_type(); + + func_inst_list_t::iterator it; + for (it = collisions.begin(); it != collisions.end(); it++) { + FuncInst * inst = *it; + if ( inst->get_type() == type ) + return inst; + } + return NULL; + } + MEMALLOC private: //ModelAction * const action; const char * position; void *location; action_type type; + + func_inst_list_t collisions; }; class FuncNode { @@ -33,14 +49,27 @@ public: HashTable * getFuncInsts() { return &func_insts; } func_inst_list_t * get_inst_list() { return &inst_list; } + uint32_t get_func_id() { return func_id; } + const char * get_func_name() { return func_name; } + void set_func_id(uint32_t id) { func_id = id; } + void set_func_name(const char * name) { func_name = name; } + MEMALLOC private: - /* Use source line number as the key of hashtable + uint32_t func_id; + const char * func_name; + + /* Use source line number as the key of hashtable, to check if + * atomic operation with this line number has been added or not * * To do: cds_atomic_compare_exchange contains three atomic operations * that are feeded with the same source line number by llvm pass */ HashTable func_insts; + /* list of all atomic instructions in this function */ func_inst_list_t inst_list; + + /* possible entry (atomic) instructions in this function */ + func_inst_list_t entry_insts; }; diff --git a/history.cc b/history.cc index 2ae49a16..c896511e 100644 --- a/history.cc +++ b/history.cc @@ -10,11 +10,13 @@ ModelHistory::ModelHistory() : func_counter(0), /* function id starts with 0 */ func_map(), + func_map_rev(), func_atomics() {} 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(); @@ -22,6 +24,7 @@ void ModelHistory::enter_function(const uint32_t func_id, thread_id_t tid) thrd_func_list->resize( id + 1 ); func_id_list_t * func_list = thrd_func_list->at(id); + if (func_list == NULL) { func_list = new func_id_list_t(); thrd_func_list->at(id) = func_list; @@ -43,6 +46,7 @@ void ModelHistory::exit_function(const uint32_t func_id, thread_id_t tid) model_print("trying to exit with a wrong function id\n"); model_print("--- last_func: %d, func_id: %d\n", last_func_id, func_id); } + //model_print("thread %d exiting func %d\n", tid, func_id); } void ModelHistory::add_func_atomic(ModelAction *act, thread_id_t tid) @@ -66,7 +70,11 @@ void ModelHistory::add_func_atomic(ModelAction *act, thread_id_t tid) FuncNode * func_node = func_atomics[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); + func_atomics[func_id] = func_node; } @@ -82,7 +90,7 @@ void ModelHistory::print() if (funcNode == NULL) continue; - model_print("function with id: %d has following actions\n", i); + model_print("function %s has following actions\n", funcNode->get_func_name()); func_inst_list_t::iterator it; for (it = inst_list->begin(); it != inst_list->end(); it++) { FuncInst *inst = *it; diff --git a/history.h b/history.h index dd8f13d8..0b523b23 100644 --- a/history.h +++ b/history.h @@ -17,6 +17,8 @@ public: void add_func_atomic(ModelAction *act, thread_id_t tid); HashTable * getFuncMap() { return &func_map; } + ModelVector * getFuncMapRev() { return &func_map_rev; } + ModelVector * getFuncAtomics() { return &func_atomics; } void print(); @@ -27,6 +29,8 @@ private: /* map function names to integer ids */ HashTable func_map; + /* map integer ids to function names */ + ModelVector func_map_rev; ModelVector func_atomics; }; -- 2.34.1