changes to handle fixed point analysis properly + bug fix.
[IRC.git] / Robust / src / Analysis / MLP / ParentChildConflictsMap.java
1 package Analysis.MLP;
2
3 import java.util.HashSet;
4 import java.util.Hashtable;
5 import java.util.Iterator;
6 import java.util.Set;
7
8 import Analysis.OwnershipAnalysis.HeapRegionNode;
9 import Analysis.OwnershipAnalysis.ReachabilitySet;
10 import Analysis.OwnershipAnalysis.ReferenceEdge;
11 import Analysis.OwnershipAnalysis.TokenTupleSet;
12 import IR.Flat.TempDescriptor;
13
14 public class ParentChildConflictsMap {
15
16         public static final Integer ACCESSIBLE = new Integer(1);
17         public static final Integer INACCESSIBLE = new Integer(2);
18
19         private Hashtable<TempDescriptor, Integer> accessibleMap;
20         private Hashtable<TempDescriptor, StallSite> stallMap;
21         private Hashtable < ReferenceEdge, StallSite > stallEdgeMap;
22
23         private boolean afterChildSESE;
24
25         public ParentChildConflictsMap() {
26
27                 accessibleMap = new Hashtable<TempDescriptor, Integer>();
28                 stallMap = new Hashtable<TempDescriptor, StallSite>();
29                 stallEdgeMap= new Hashtable < ReferenceEdge, StallSite >();
30                 afterChildSESE=false;
31
32         }
33         
34         public Hashtable < ReferenceEdge, StallSite > getStallEdgeMap(){
35                 return stallEdgeMap;
36         }
37         
38         public void addStallEdge(ReferenceEdge edge, StallSite site){
39                 stallEdgeMap.put(edge, site);
40         }
41         
42         public StallSite getStallSiteByEdge(ReferenceEdge edge){
43                 return stallEdgeMap.get(edge);
44         }
45         
46         public void setAfterChildSESE(boolean b){
47                 this.afterChildSESE=b;
48         }
49         
50         public boolean isAfterChildSESE(){
51                 return afterChildSESE;
52         }
53
54         public Hashtable<TempDescriptor, Integer> getAccessibleMap() {
55                 return accessibleMap;
56         }
57
58         public Hashtable<TempDescriptor, StallSite> getStallMap() {
59                 return stallMap;
60         }
61
62         public void addAccessibleVar(TempDescriptor td) {
63                 accessibleMap.put(td, ACCESSIBLE);
64         }
65
66         public void addInaccessibleVar(TempDescriptor td) {
67                 accessibleMap.put(td, INACCESSIBLE);
68         }
69
70         public void addStallSite(TempDescriptor td, HashSet<HeapRegionNode> heapSet) {
71                 StallSite stallSite=new StallSite(heapSet);
72                 stallMap.put(td, stallSite);
73         }
74         
75         public void addStallSite(TempDescriptor td, StallSite stallSite) {
76                 stallMap.put(td, stallSite);
77         }
78
79         public boolean hasStallSite(TempDescriptor td){
80                 return stallMap.containsKey(td);
81         }
82
83         public boolean isAccessible(TempDescriptor td) {
84                 if (accessibleMap.containsKey(td)
85                                 && accessibleMap.get(td).equals(ACCESSIBLE)) {
86                         return true;
87                 }
88                 return false;
89         }
90
91         public void contributeEffect(TempDescriptor td, String type, String field,
92                         int effect) {
93
94                 StallSite stallSite = stallMap.get(td);
95                 if (stallSite != null) {
96                         stallSite.addEffect(type, field, effect);
97                 }
98
99         }
100
101         public void merge(ParentChildConflictsMap newConflictsMap) {
102                 
103                 if(afterChildSESE==false && newConflictsMap.isAfterChildSESE()){
104                         this.afterChildSESE=true;
105                 }
106
107                 Hashtable<TempDescriptor, Integer> newAccessibleMap = newConflictsMap
108                                 .getAccessibleMap();
109                 Hashtable<TempDescriptor, StallSite> newStallMap = newConflictsMap
110                                 .getStallMap();
111
112                 Set<TempDescriptor> keySet = newAccessibleMap.keySet();
113                 for (Iterator<TempDescriptor> iterator = keySet.iterator(); iterator
114                                 .hasNext();) {
115                         TempDescriptor key = iterator.next();
116
117                         Integer newStatus = newAccessibleMap.get(key);
118
119                         // inaccessible is prior to accessible
120                         Integer currentStatus = getAccessibleMap().get(key);
121                         if (currentStatus != null && currentStatus == ACCESSIBLE
122                                         && newStatus == INACCESSIBLE) {
123                                 getAccessibleMap().put(key, INACCESSIBLE);
124                         }
125                 }
126
127                 keySet = newStallMap.keySet();
128                 for (Iterator<TempDescriptor> iterator = keySet.iterator(); iterator
129                                 .hasNext();) {
130                         TempDescriptor key = iterator.next();
131
132                         StallSite newStallSite = newStallMap.get(key);
133                         StallSite currentStallSite = getStallMap().get(key);
134                         
135                         if(currentStallSite==null){
136                                 currentStallSite=new StallSite();
137                         }
138
139                         // handle effects
140                         HashSet<Effect> currentEffectSet = currentStallSite.getEffectSet();
141                         HashSet<Effect> newEffectSet = newStallSite.getEffectSet();
142                         for (Iterator iterator2 = newEffectSet.iterator(); iterator2
143                                         .hasNext();) {
144                                 Effect effect = (Effect) iterator2.next();
145                                 if (!currentEffectSet.contains(effect)) {
146                                         currentEffectSet.add(effect);
147                                 }
148                         }
149
150                         // handle heap region
151                         HashSet<HeapRegionNode> currentHRNSet = currentStallSite.getHRNSet();
152                         HashSet<HeapRegionNode> newHRNSet = newStallSite.getHRNSet();
153                         for (Iterator iterator2 = newHRNSet.iterator(); iterator2.hasNext();) {
154                                 HeapRegionNode hrnID = (HeapRegionNode) iterator2.next();
155                                 if (!currentHRNSet.contains(hrnID)) {
156                                         currentHRNSet.add(hrnID);
157                                 }
158                         }
159
160                         // handle reachabilitySet
161                         ReachabilitySet currentRSet = currentStallSite.getReachabilitySet();
162                         ReachabilitySet newRSet = newStallSite.getReachabilitySet();
163                         Iterator<TokenTupleSet> ttsIter = newRSet.iterator();
164                         while (ttsIter.hasNext()) {
165                                 TokenTupleSet tokenTupleSet = (TokenTupleSet) ttsIter.next();
166                                 currentRSet.add(tokenTupleSet);
167                         }
168                         
169                         StallSite merged=new StallSite(currentEffectSet, currentHRNSet,
170                                         currentRSet);
171
172                         getStallMap()
173                                         .put(
174                                                         key,
175                                                         merged);
176
177                 }
178                 
179                 // merge edge mapping
180                 
181                 Hashtable<ReferenceEdge, StallSite> newStallEdgeMapping=newConflictsMap.getStallEdgeMap();
182                 Set<ReferenceEdge> edgeSet=newStallEdgeMapping.keySet();
183                 for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) {
184                         ReferenceEdge stallEdge = (ReferenceEdge) iterator.next();
185                         StallSite newStallSite=newStallEdgeMapping.get(stallEdge);
186                         getStallEdgeMap().put(stallEdge, newStallSite);
187                 }
188
189         }
190         
191         public boolean equals(Object o) {
192
193                 if (o == null) {
194                         return false;
195                 }
196
197                 if (!(o instanceof ParentChildConflictsMap)) {
198                         return false;
199                 }
200
201                 ParentChildConflictsMap in = (ParentChildConflictsMap) o;
202
203                 if (afterChildSESE==in.isAfterChildSESE() && accessibleMap.equals(in.getAccessibleMap())
204                                 && stallMap.equals(in.getStallMap())) {
205                         return true;
206                 } else {
207                         return false;
208                 }
209
210         }
211
212         public String toString() {
213                 return "ParentChildConflictsMap [accessibleMap=" + accessibleMap
214                                 + ", afterChildSESE=" + afterChildSESE + ", stallMap="
215                                 + stallMap + "]";
216         }
217
218 }