Merge branch 'new_fuzzer' into tmp
[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 addEdge(const ModelAction *from, const ModelAction *to);
27         void addRMWEdge(const ModelAction *from, const ModelAction *rmw);
28         bool checkReachable(const ModelAction *from, const ModelAction *to) const;
29
30 #if SUPPORT_MOD_ORDER_DUMP
31         void dumpNodes(FILE *file) const;
32         void dumpGraphToFile(const char *filename) const;
33         void dot_print_node(FILE *file, const ModelAction *act);
34         void dot_print_edge(FILE *file, const ModelAction *from, const ModelAction *to, const char *prop);
35 #endif
36
37         CycleNode * getNode_noCreate(const ModelAction *act) const;
38         SNAPSHOTALLOC
39 private:
40         void addNodeEdge(CycleNode *fromnode, CycleNode *tonode);
41         void putNode(const ModelAction *act, CycleNode *node);
42         CycleNode * getNode(const ModelAction *act);
43
44         /** @brief A table for mapping ModelActions to CycleNodes */
45         HashTable<const ModelAction *, CycleNode *, uintptr_t, 4> actionToNode;
46         SnapVector<const CycleNode *> * queue;
47
48 #if SUPPORT_MOD_ORDER_DUMP
49         SnapVector<CycleNode *> nodeList;
50 #endif
51
52         bool checkReachable(const CycleNode *from, const CycleNode *to) const;
53 };
54
55 /**
56  * @brief A node within a CycleGraph; corresponds either to one ModelAction
57  */
58 class CycleNode {
59 public:
60         CycleNode(const ModelAction *act);
61         void addEdge(CycleNode *node);
62         CycleNode * getEdge(unsigned int i) const;
63         unsigned int getNumEdges() const;
64         CycleNode * removeEdge();
65         bool setRMW(CycleNode *);
66         CycleNode * getRMW() const;
67         void clearRMW() { hasRMW = NULL; }
68         const ModelAction * getAction() const { return action; }
69
70         SNAPSHOTALLOC
71 private:
72         /** @brief The ModelAction that this node represents */
73         const ModelAction *action;
74
75         /** @brief The edges leading out from this node */
76         SnapVector<CycleNode *> edges;
77
78         /** Pointer to a RMW node that reads from this node, or NULL, if none
79          * exists */
80         CycleNode *hasRMW;
81
82         /** ClockVector for this Node. */
83         ClockVector *cv;
84         friend class CycleGraph;
85 };
86
87 #endif  /* __CYCLEGRAPH_H__ */