Add SCFence analysis
[c11tester.git] / scfence / scgen.h
1 #ifndef _SCGEN_H
2 #define _SCGEN_H
3
4 #include "hashtable.h"
5 #include "memoryorder.h"
6 #include "action.h"
7 #include "scanalysis.h"
8 #include "model.h"
9 #include "execution.h"
10 #include "threads-model.h"
11 #include "clockvector.h"
12 #include "sc_annotation.h"
13
14 #include <sys/time.h>
15
16 typedef struct SCGeneratorOption {
17         bool print_always;
18         bool print_buggy;
19         bool print_nonsc;
20         bool annotationMode;
21 } SCGeneratorOption;
22
23
24 class SCGenerator {
25 public:
26         SCGenerator();
27         ~SCGenerator();
28
29         bool getCyclic();
30         SnapVector<action_list_t>* getDupThreadLists();
31
32         struct sc_statistics* getStats();
33
34         void setExecution(ModelExecution *execution);
35         void setActions(action_list_t *actions);
36         void setPrintAlways(bool val);
37         bool getPrintAlways();
38         bool getHasBadRF();
39
40         void setAnnotationMode(bool val);
41
42         void setPrintBuggy(bool val);
43         
44         void setPrintNonSC(bool val);
45
46         action_list_t * getSCList();
47         
48         HashTable<const ModelAction *, const ModelAction *, uintptr_t, 4> *getBadrfset();
49
50         HashTable<const ModelAction *, const ModelAction *, uintptr_t, 4 > *getAnnotatedReadSet();
51
52         void print_list(action_list_t *list);
53
54         SNAPSHOTALLOC
55 private:
56         /********************** SC-related stuff (beginning) **********************/
57         ModelExecution *execution;
58
59         action_list_t *actions;
60
61         bool fastVersion;
62         bool allowNonSC;
63
64         action_list_t * generateSC(action_list_t *list);
65
66         void update_stats();
67
68         int buildVectors(SnapVector<action_list_t> *threadlist, int *maxthread,
69                 action_list_t *list);
70
71         bool updateConstraints(ModelAction *act);
72
73         void computeCV(action_list_t *list);
74
75         bool processReadFast(ModelAction *read, ClockVector *cv);
76
77         bool processReadSlow(ModelAction *read, ClockVector *cv, bool *updateFuture);
78
79         bool processAnnotatedReadSlow(ModelAction *read, ClockVector *cv, bool *updateFuture);
80
81         int getNextActions(ModelAction **array);
82
83         bool merge(ClockVector *cv, const ModelAction *act, const ModelAction *act2);
84
85         void check_rf(action_list_t *list);
86         void check_rf1(action_list_t *list);
87         
88         void reset(action_list_t *list);
89         
90         ModelAction* pruneArray(ModelAction **array, int count);
91
92         /** This routine is operated based on the built threadlists */
93         void collectAnnotatedReads();
94
95         int maxthreads;
96         HashTable<const ModelAction *, ClockVector *, uintptr_t, 4 > cvmap;
97         bool cyclic;
98         HashTable<const ModelAction *, const ModelAction *, uintptr_t, 4 > badrfset;
99         HashTable<void *, const ModelAction *, uintptr_t, 4 > lastwrmap;
100         SnapVector<action_list_t> threadlists;
101         SnapVector<action_list_t> dup_threadlists;
102         bool print_always;
103         bool print_buggy;
104         bool print_nonsc;
105         bool hasBadRF;
106
107         struct sc_statistics *stats;
108
109         /** The set of read actions that are annotated to be special and will
110          *  receive special treatment */
111         HashTable<const ModelAction *, const ModelAction *, uintptr_t, 4 > annotatedReadSet;
112         int annotatedReadSetSize;
113         bool annotationMode;
114         bool annotationError;
115
116         /** A set of actions that should be ignored in the partially SC analysis */
117         HashTable<const ModelAction*, const ModelAction*, uintptr_t, 4> ignoredActions;
118 };
119 #endif