More pieces for new version of analysis
[IRC.git] / Robust / src / Analysis / MLP / StallSite.java
1 package Analysis.MLP;
2
3 import java.util.HashSet;
4 import java.util.Iterator;
5 import java.util.Set;
6
7 import Analysis.OwnershipAnalysis.AllocationSite;
8 import Analysis.OwnershipAnalysis.HeapRegionNode;
9 import Analysis.OwnershipAnalysis.TokenTupleSet;
10 import IR.Flat.FlatNode;
11 import IR.Flat.TempDescriptor;
12
13 public class StallSite {
14
15         public static final Integer READ_EFFECT = new Integer(1);
16         public static final Integer WRITE_EFFECT = new Integer(2);
17
18         private HashSet<Effect> effectSet;
19         private HashSet<HeapRegionNode> hrnSet;
20         private HashSet<AllocationSite> allocationSiteSet;
21 //      private ReachabilitySet reachabilitySet;
22         HashSet<TokenTupleSet> reachabilitySet;
23         private HashSet<StallTag> stallTagSet;
24         private TempDescriptor tdA;
25
26         // if stall site is caller's parameter heap regtion, store its parameter idx
27         // for further analysis
28         private HashSet<Integer> callerParamIdxSet;
29
30         public StallSite() {
31                 effectSet = new HashSet<Effect>();
32                 hrnSet = new HashSet<HeapRegionNode>();
33                 reachabilitySet = new HashSet<TokenTupleSet>();
34                 allocationSiteSet = new HashSet<AllocationSite>();
35                 stallTagSet = new HashSet<StallTag>();
36                 callerParamIdxSet = new HashSet<Integer>();
37         }
38         
39         public StallSite(HashSet<HeapRegionNode> hrnSet, StallTag tag) {
40
41                 this();
42
43                 setHeapRegionNodeSet(hrnSet);
44                 stallTagSet.add(tag);
45
46                 for (Iterator iterator = hrnSet.iterator(); iterator.hasNext();) {
47                         HeapRegionNode heapRegionNode = (HeapRegionNode) iterator.next();
48                         setAllocationSite(heapRegionNode.getAllocationSite());
49                 }
50         }
51         
52         public StallSite(HashSet<Effect> effectSet, HashSet<HeapRegionNode> hrnSet,
53                         HashSet<TokenTupleSet> rechabilitySet, HashSet<AllocationSite> alocSet,
54                         HashSet<StallTag> tagSet, HashSet<Integer> paramIdx) {
55                 this();
56                 this.effectSet.addAll(effectSet);
57                 this.hrnSet.addAll(hrnSet);
58                 this.reachabilitySet = rechabilitySet;
59                 this.allocationSiteSet.addAll(alocSet);
60                 this.stallTagSet.addAll(tagSet);
61                 this.callerParamIdxSet.addAll(paramIdx);
62         }
63         
64         public void addTokenTupleSet(TokenTupleSet newSet){
65                 reachabilitySet.add(newSet);
66         }
67
68         public HashSet<Integer> getCallerParamIdxSet() {
69                 return callerParamIdxSet;
70         }
71
72         public void addCallerParamIdxSet(Set<Integer> newParamSet) {
73                 if (newParamSet != null) {
74                         callerParamIdxSet.addAll(newParamSet);
75                 }
76         }
77
78         public void setStallTagSet(HashSet<StallTag> tags) {
79                 stallTagSet = tags;
80         }
81
82         public void addRelatedStallTag(StallTag stallTag) {
83                 stallTagSet.add(stallTag);
84         }
85
86         public void setAllocationSite(AllocationSite allocationSite) {
87                 if (allocationSite != null) {
88                         allocationSiteSet.add(allocationSite);
89                 }
90         }
91
92         public void setHeapRegionNodeSet(HashSet<HeapRegionNode> newSet) {
93                 hrnSet.addAll(newSet);
94         }
95
96         public HashSet<AllocationSite> getAllocationSiteSet() {
97                 return allocationSiteSet;
98         }
99
100         public void addEffect(String type, String field, Integer effect) {
101
102                 Effect e = new Effect(type, field, effect, stallTagSet);
103                 effectSet.add(e);
104         }
105
106         public HashSet<Effect> getEffectSet() {
107                 return effectSet;
108         }
109
110         public HashSet<HeapRegionNode> getHRNSet() {
111                 return hrnSet;
112         }
113
114         public HashSet<TokenTupleSet> getReachabilitySet() {
115                 return reachabilitySet;
116         }
117
118         public HashSet<StallTag> getStallTagSet() {
119                 return stallTagSet;
120         }
121
122         public StallSite copy() {
123
124                 StallSite copy = new StallSite(effectSet, hrnSet, reachabilitySet,
125                                 allocationSiteSet, stallTagSet, callerParamIdxSet);
126                 return copy;
127                 
128         }
129         
130         public void setTdA(TempDescriptor tdA){
131                 this.tdA=tdA;
132         }
133         
134         public TempDescriptor getTdA(){
135                 return tdA;
136         }
137
138         public boolean equals(Object o) {
139
140                 if (o == null) {
141                         return false;
142                 }
143
144                 if (!(o instanceof StallSite)) {
145                         return false;
146                 }
147
148                 StallSite in = (StallSite) o;
149
150                 if (allocationSiteSet.equals(in.getAllocationSiteSet())
151                                 && stallTagSet.equals(in.getStallTagSet())
152                                 && effectSet.equals(in.getEffectSet())
153                                 && hrnSet.equals(in.getHRNSet())
154                                 && reachabilitySet.equals(in.getReachabilitySet())) {
155                         return true;
156                 } else {
157                         return false;
158                 }
159
160         }
161
162         @Override
163         public String toString() {
164                 return "StallSite [allocationSiteSet=" + allocationSiteSet
165                                 + ", callerParamIdxSet=" + callerParamIdxSet + ", effectSet="
166                                 + effectSet + ", hrnSet=" + hrnSet + ", rechabilitySet="
167                                 + reachabilitySet + ", stallTagSet=" + stallTagSet + "]";
168         }
169
170 }
171
172 class StallTag {
173
174         private FlatNode fn;
175
176         public StallTag(FlatNode fn) {
177                 this.fn = fn;
178         }
179
180         public FlatNode getKey() {
181                 return fn;
182         }
183
184         public boolean equals(Object o) {
185
186                 if (o == null) {
187                         return false;
188                 }
189
190                 if (!(o instanceof StallTag)) {
191                         return false;
192                 }
193
194                 StallTag in = (StallTag) o;
195
196                 if (getKey().equals(in.getKey())) {
197                         return true;
198                 } else {
199                         return false;
200                 }
201
202         }
203
204 }
205
206 class Effect {
207
208         private String field;
209         private String type;
210         private Integer effect;
211         private HashSet<StallTag> stallTagSet;
212
213         public Effect() {
214                 stallTagSet = new HashSet<StallTag>();
215         }
216
217         public Effect(String type, String field, Integer effect,
218                         HashSet<StallTag> tagSet) {
219                 this();
220                 this.type = type;
221                 this.field = field;
222                 this.effect = effect;
223                 stallTagSet.addAll(tagSet);
224         }
225
226         public String getField() {
227                 return field;
228         }
229
230         public String getType() {
231                 return type;
232         }
233
234         public Integer getEffectType() {
235                 return effect;
236         }
237
238         public HashSet<StallTag> getStallTagSet() {
239                 return stallTagSet;
240         }
241
242         public boolean equals(Object o) {
243
244                 if (o == null) {
245                         return false;
246                 }
247
248                 if (!(o instanceof Effect)) {
249                         return false;
250                 }
251
252                 Effect in = (Effect) o;
253
254                 if (stallTagSet.equals(in.getStallTagSet())
255                                 && type.equals(in.getType()) && field.equals(in.getField())
256                                 && effect.equals(in.getEffectType())) {
257                         return true;
258                 } else {
259                         return false;
260                 }
261
262         }
263
264         public String toString() {
265                 return "Effect [effect=" + effect + ", field=" + field
266                                 + ", stallTagSet=" + stallTagSet + ", type=" + type + "]";
267         }
268
269 }