commit stuff before merge
authorweiyu <weiyuluo1232@gmail.com>
Thu, 11 Jul 2019 23:38:06 +0000 (16:38 -0700)
committerweiyu <weiyuluo1232@gmail.com>
Thu, 11 Jul 2019 23:38:06 +0000 (16:38 -0700)
funcinst.cc
funcinst.h
funcnode.cc
funcnode.h

index d3593fb7189f6a3a938726eac6fa5cbba68c9ca0..61e3d92290c34b354cb16ccf15c6f26ca9e251cd 100644 (file)
@@ -17,7 +17,8 @@ FuncInst::FuncInst(ModelAction *act, FuncNode *func_node) :
  * @return false: other is already in predecessors
  *         true : other is added to precedessors
  */
-bool FuncInst::add_pred(FuncInst * other) {
+bool FuncInst::add_pred(FuncInst * other)
+{
        func_inst_list_mt::iterator it;
        for (it = predecessors.begin(); it != predecessors.end(); it++) {
                FuncInst * inst = *it;
@@ -29,7 +30,8 @@ bool FuncInst::add_pred(FuncInst * other) {
        return true;
 }
 
-bool FuncInst::add_succ(FuncInst * other) {
+bool FuncInst::add_succ(FuncInst * other)
+{
        func_inst_list_mt::iterator it;
        for (it = successors.begin(); it != successors.end(); it++) {
                FuncInst * inst = *it;
@@ -41,7 +43,8 @@ bool FuncInst::add_succ(FuncInst * other) {
        return true;
 }
 
-FuncInst * FuncInst::search_in_collision(ModelAction *act) {
+FuncInst * FuncInst::search_in_collision(ModelAction *act)
+{
        action_type type = act->get_type();
 
        func_inst_list_mt::iterator it;
@@ -52,3 +55,8 @@ FuncInst * FuncInst::search_in_collision(ModelAction *act) {
        }
        return NULL;
 }
+
+bool FuncInst::is_read() const
+{
+       return type == ATOMIC_READ || type == ATOMIC_RMWR || type == ATOMIC_RMWRCAS;
+}
index 6cb8c1a1510ac7df84ca76f6d2fce05a91297592..85b9c20ecce2d9b07d8b85168fc3f1bbe39701b4 100644 (file)
@@ -25,6 +25,8 @@ public:
        func_inst_list_mt * get_preds() { return &predecessors; }
        func_inst_list_mt * get_succs() { return &successors; }
 
+       bool is_read() const;
+
        MEMALLOC
 private:
        //ModelAction * const action;
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);
+}
index 3d3aaa4c852cbb8d044b8750acef7316553d2bc5..51f19f0cce65812a9771c60e796093357e024911 100644 (file)
@@ -18,11 +18,13 @@ public:
 
        FuncInst * get_or_add_action(ModelAction *act);
 
-       HashTable<const char *, FuncInst *, uintptr_t, 4, model_malloc, model_calloc, model_free> * getFuncInsts() { return &func_insts; }
+       HashTable<const char *, FuncInst *, uintptr_t, 4, model_malloc, model_calloc, model_free> * getFuncInstMap() { return &func_inst_map; }
        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 group_reads_by_loc(FuncInst * inst);
+
        MEMALLOC
 private:
        uint32_t func_id;
@@ -34,11 +36,14 @@ private:
         * To do: cds_atomic_compare_exchange contains three atomic operations
         * that are feeded with the same source line number by llvm pass
         */
-       HashTable<const char *, FuncInst *, uintptr_t, 4, model_malloc, model_calloc, model_free> func_insts;
+       HashTable<const char *, FuncInst *, uintptr_t, 4, model_malloc, model_calloc, model_free> func_inst_map;
 
-       /* list of all atomic instructions in this function */
+       /* list of all atomic actions in this function */
        func_inst_list_mt inst_list;
 
-       /* possible entry atomic instructions in this function */
+       /* possible entry atomic actions in this function */
        func_inst_list_mt entry_insts;
+
+       /* group atomic read actions by memory location */
+       HashTable<void *, func_inst_list_mt *, uintptr_t, 4, model_malloc, model_calloc, model_free> reads_by_loc;
 };