do optimization for FuncNode::update_tree
[c11tester.git] / cyclegraph.h
1 /**
2  * @file cyclegraph.h
3  * @brief Data structure to track ordering constraints on modification order
4  *
5  * Used to determine whether a total order exists that satisfies the ordering
6  * constraints.
7  */
8
9 #ifndef __CYCLEGRAPH_H__
10 #define __CYCLEGRAPH_H__
11
12 #include <inttypes.h>
13 #include <stdio.h>
14
15 #include "hashtable.h"
16 #include "config.h"
17 #include "mymemory.h"
18 #include "stl-model.h"
19 #include "classlist.h"
20
21 /** @brief A graph of Model Actions for tracking cycles. */
22 class CycleGraph {
23 public:
24         CycleGraph();
25         ~CycleGraph();
26         void addEdges(SnapList<ModelAction *> * edgeset, const ModelAction *to);
27         void addEdge(const ModelAction *from, const ModelAction *to);
28         void addEdge(const ModelAction *from, const ModelAction *to, bool forceedge);
29         void addRMWEdge(const ModelAction *from, const ModelAction *rmw);
30         bool checkReachable(const ModelAction *from, const ModelAction *to) const;
31
32 #if SUPPORT_MOD_ORDER_DUMP
33         void dumpNodes(FILE *file) const;
34         void dumpGraphToFile(const char *filename) const;
35         void dot_print_node(FILE *file, const ModelAction *act);
36         void dot_print_edge(FILE *file, const ModelAction *from, const ModelAction *to, const char *prop);
37 #endif
38
39         CycleNode * getNode_noCreate(const ModelAction *act) const;
40         SNAPSHOTALLOC
41 private:
42         void addNodeEdge(CycleNode *fromnode, CycleNode *tonode, bool forceedge);
43         void putNode(const ModelAction *act, CycleNode *node);
44         CycleNode * getNode(const ModelAction *act);
45
46         /** @brief A table for mapping ModelActions to CycleNodes */
47         HashTable<const ModelAction *, CycleNode *, uintptr_t, 4> actionToNode;
48         SnapVector<const CycleNode *> * queue;
49
50 #if SUPPORT_MOD_ORDER_DUMP
51         SnapVector<CycleNode *> nodeList;
52 #endif
53
54         bool checkReachable(const CycleNode *from, const CycleNode *to) const;
55 };
56
57 /**
58  * @brief A node within a CycleGraph; corresponds either to one ModelAction
59  */
60 class CycleNode {
61 public:
62         CycleNode(const ModelAction *act);
63         void addEdge(CycleNode *node);
64         CycleNode * getEdge(unsigned int i) const;
65         unsigned int getNumEdges() const;
66         CycleNode * removeEdge();
67         bool setRMW(CycleNode *);
68         CycleNode * getRMW() const;
69         void clearRMW() { hasRMW = NULL; }
70         const ModelAction * getAction() const { return action; }
71
72         SNAPSHOTALLOC
73 private:
74         /** @brief The ModelAction that this node represents */
75         const ModelAction *action;
76
77         /** @brief The edges leading out from this node */
78         SnapVector<CycleNode *> edges;
79
80         /** Pointer to a RMW node that reads from this node, or NULL, if none
81          * exists */
82         CycleNode *hasRMW;
83
84         /** ClockVector for this Node. */
85         ClockVector *cv;
86         friend class CycleGraph;
87 };
88
89 #endif  /* __CYCLEGRAPH_H__ */