commit stuff before merge
[c11tester.git] / funcnode.cc
index 1f59a548a13987177e20603e5139da9f0a5571e8..ce91815f7c8ac2ff860f22287a5e8b649465ce31 100644 (file)
@@ -1,15 +1,19 @@
 #include "funcnode.h"
 
 FuncNode::FuncNode() :
-       func_insts(),
+       func_inst_map(),
        inst_list(),
        entry_insts()
 {}
 
+/* Check whether FuncInst with the same type, position, and location 
+ * as act has been added to func_inst_map or not. If so, return it;
+ * if not, add it and return it.
+ *
+ * @return FuncInst with the same type, position, and location as act */
 FuncInst * FuncNode::get_or_add_action(ModelAction *act)
 {
        ASSERT(act);
-
        const char * position = act->get_position();
 
        /* Actions THREAD_CREATE, THREAD_START, THREAD_YIELD, THREAD_JOIN,
@@ -20,8 +24,8 @@ FuncInst * FuncNode::get_or_add_action(ModelAction *act)
        if (position == NULL)
                return NULL;
 
-       if ( func_insts.contains(position) ) {
-               FuncInst * inst = func_insts.get(position);
+       if ( func_inst_map.contains(position) ) {
+               FuncInst * inst = func_inst_map.get(position);
 
                if (inst->get_type() != act->get_type() ) {
                        // model_print("action with a different type occurs at line number %s\n", position);
@@ -35,8 +39,9 @@ FuncInst * FuncNode::get_or_add_action(ModelAction *act)
                        func_inst = new FuncInst(act, this);
                        inst->get_collisions()->push_back(func_inst);
                        inst_list.push_back(func_inst);         // delete?
-                       // model_print("collision added\n");
-                       
+                       if (func_inst->is_read())
+                               group_reads_by_loc(func_inst);
+
                        return func_inst;
                }
 
@@ -44,9 +49,12 @@ FuncInst * FuncNode::get_or_add_action(ModelAction *act)
        }
 
        FuncInst * func_inst = new FuncInst(act, this);
-       func_insts.put(position, func_inst);
-
+       func_inst_map.put(position, func_inst);
        inst_list.push_back(func_inst);
+
+       if (func_inst->is_read())
+               group_reads_by_loc(func_inst);
+
        return func_inst;
 }
 
@@ -63,3 +71,30 @@ void FuncNode::add_entry_inst(FuncInst * inst)
 
        entry_insts.push_back(inst);
 }
+
+/* group atomic read actions by memory location */
+void FuncNode::group_reads_by_loc(FuncInst * inst)
+{
+       ASSERT(inst);
+       if ( !inst->is_read() )
+               return;
+
+       void * location = inst->get_location();
+
+       func_inst_list_mt * reads;
+       if ( !reads_by_loc.contains(location) ) {
+               reads = new func_inst_list_mt();
+               reads->push_back(inst);
+               reads_by_loc.put(location, reads);
+               return;
+       }
+
+       reads = reads_by_loc.get(location);
+       func_inst_list_mt::iterator it;
+       for (it = reads->begin(); it != reads->end(); it++) {
+               if (inst == *it)
+                       return;
+       }
+
+       reads->push_back(inst);
+}