3b6c30197e78f5f7a840a3972601ea5edcdeb870
[IRC.git] / Robust / src / Analysis / OoOJava / ConflictNode.java
1 package Analysis.OoOJava;
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.Disjoint.Alloc;
9 import Analysis.Disjoint.AllocSite;
10 import Analysis.Disjoint.Effect;
11 import Analysis.Disjoint.Taint;
12 import IR.Flat.FlatNew;
13 import IR.Flat.FlatNode;
14 import IR.Flat.FlatSESEEnterNode;
15 import IR.Flat.TempDescriptor;
16
17 public class ConflictNode {
18
19   protected HashSet<ConflictEdge> edgeSet;
20   protected HashSet<Alloc> allocSet;
21   protected HashSet<Taint> taintSet;
22
23   protected Hashtable<Alloc, Set<Effect>> alloc2readEffectSet;
24   protected Hashtable<Alloc, Set<Effect>> alloc2writeEffectSet;
25   protected Hashtable<Alloc, Set<Effect>> alloc2strongUpdateEffectSet;
26
27   protected int nodeType;
28   protected String id;
29   protected FlatNode stallSite;
30   protected TempDescriptor var;
31   protected FlatSESEEnterNode fsen;
32   protected boolean toBePruned = false;
33
34   public boolean isTobePruned() {
35     return toBePruned;
36   }
37
38   public void setToBePruned(boolean toBePruned) {
39     this.toBePruned = toBePruned;
40   }
41
42   public static final int FINE_READ = 0;
43   public static final int FINE_WRITE = 1;
44   public static final int PARENT_READ = 2;
45   public static final int PARENT_WRITE = 3;
46   public static final int COARSE = 4;
47   public static final int PARENT_COARSE = 5;
48   public static final int SCC = 6;
49
50   public static final int INVAR = 0;
51   public static final int STALLSITE = 1;
52
53   public ConflictNode(String id, int nodeType, TempDescriptor var, FlatNode stallSite) {
54     this(id, var, nodeType);
55     this.stallSite = stallSite;
56   }
57
58   public ConflictNode(String id, int nodeType, TempDescriptor var, FlatSESEEnterNode fsen) {
59     this(id, var, nodeType);
60     this.fsen = fsen;
61   }
62
63   public ConflictNode(String id, TempDescriptor var, int nodeType) {
64     edgeSet = new HashSet<ConflictEdge>();
65     // redundant views of access root's
66     // allocation sites for efficient retrieval
67     allocSet = new HashSet<Alloc>();
68     taintSet = new HashSet<Taint>();
69
70     alloc2readEffectSet = new Hashtable<Alloc, Set<Effect>>();
71     alloc2writeEffectSet = new Hashtable<Alloc, Set<Effect>>();
72     alloc2strongUpdateEffectSet = new Hashtable<Alloc, Set<Effect>>();
73
74     this.id = id;
75     this.nodeType = nodeType;
76     this.var = var;
77   }
78
79   public void addTaint(Taint t) {
80     taintSet.add(t);
81   }
82
83   public Taint getTaint(Alloc as) {
84     for (Iterator iterator = taintSet.iterator(); iterator.hasNext();) {
85       Taint t = (Taint) iterator.next();
86       if (t.getAllocSite().equals(as)) {
87         return t;
88       }
89     }
90     return null;
91   }
92
93   public void addEffect(Alloc as, Effect e) {
94     if (e.getType() == Effect.read) {
95       addReadEffect(as, e);
96     } else if (e.getType() == Effect.write) {
97       addWriteEffect(as, e);
98     } else {
99       addStrongUpdateEffect(as, e);
100     }
101   }
102
103   public void addReadEffect(Alloc as, Effect e) {
104     allocSet.add(as);
105     Set<Effect> effectSet = alloc2readEffectSet.get(as);
106     if (effectSet == null) {
107       effectSet = new HashSet<Effect>();
108     }
109     effectSet.add(e);
110
111     alloc2readEffectSet.put(as, effectSet);
112   }
113
114   public void addWriteEffect(Alloc as, Effect e) {
115     allocSet.add(as);
116     Set<Effect> effectSet = alloc2writeEffectSet.get(as);
117     if (effectSet == null) {
118       effectSet = new HashSet<Effect>();
119     }
120     effectSet.add(e);
121
122     alloc2writeEffectSet.put(as, effectSet);
123   }
124
125   public void addStrongUpdateEffect(Alloc as, Effect e) {
126     allocSet.add(as);
127     Set<Effect> effectSet = alloc2strongUpdateEffectSet.get(as);
128     if (effectSet == null) {
129       effectSet = new HashSet<Effect>();
130     }
131     effectSet.add(e);
132
133     alloc2strongUpdateEffectSet.put(as, effectSet);
134   }
135
136   public Hashtable<Alloc, Set<Effect>> getReadEffectSet() {
137     return alloc2readEffectSet;
138   }
139
140   public Hashtable<Alloc, Set<Effect>> getWriteEffectSet() {
141     return alloc2writeEffectSet;
142   }
143
144   public Hashtable<Alloc, Set<Effect>> getStrongUpdateEffectSet() {
145     return alloc2strongUpdateEffectSet;
146   }
147
148   public boolean isInVarNode() {
149     if (nodeType == ConflictNode.INVAR) {
150       return true;
151     }
152     return false;
153   }
154
155   public boolean isStallSiteNode() {
156     return !isInVarNode();
157   }
158
159   public Set<FlatNew> getFlatNewSet() {
160     Set<FlatNew> fnSet = new HashSet<FlatNew>();
161     for (Iterator iterator = allocSet.iterator(); iterator.hasNext();) {
162       Alloc as = (Alloc) iterator.next();
163       FlatNew fn = as.getFlatNew();
164       fnSet.add(fn);
165     }
166     return fnSet;
167   }
168
169   public TempDescriptor getVar() {
170     return var;
171   }
172
173   public Set<ConflictEdge> getEdgeSet() {
174     return edgeSet;
175   }
176
177   public void addEdge(ConflictEdge edge) {
178     edgeSet.add(edge);
179   }
180
181   public String getID() {
182     return id;
183   }
184
185   public FlatNode getStallSiteFlatNode() {
186     return stallSite;
187   }
188
189   public int getSESEIdentifier() {
190     return fsen.getIdentifier();
191   }
192
193   public boolean equals(Object o) {
194
195     if (o == null) {
196       return false;
197     }
198
199     if (!(o instanceof ConflictNode)) {
200       return false;
201     }
202
203     ConflictNode in = (ConflictNode) o;
204
205     if (id.equals(in.id)) {
206       return true;
207     } else {
208       return false;
209     }
210
211   }
212
213   public String toStringAllEffects() {
214
215     String str = "";
216
217     if (!alloc2readEffectSet.isEmpty()) {
218       str += "read effect= " + alloc2readEffectSet.toString() + "\n";
219     }
220
221     if (!alloc2writeEffectSet.isEmpty()) {
222       str += "write effect = " + alloc2writeEffectSet.toString() + "\n";
223     }
224
225     if (!alloc2strongUpdateEffectSet.isEmpty()) {
226       str += "SU effect = " + alloc2strongUpdateEffectSet.toString() + "\n";
227     }
228
229     return str;
230   }
231
232   public String toString() {
233     return id;
234   }
235
236   public boolean IsValidToPrune() {
237
238     for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) {
239       ConflictEdge edge = (ConflictEdge) iterator.next();
240
241       if (edge.getVertexU() == edge.getVertexV()) {
242         // self-conflict, need to generate traverser
243         return false;
244       } else {
245
246         if (edge.getVertexU() == this) {
247           if (edge.getVertexV().isInVarNode()) {
248             // has a conflict with invar, need to generate traverser
249             return false;
250           }
251         } else {
252           if (edge.getVertexU().isInVarNode()) {
253             // has a conflict with invar, need to generate traverser
254             return false;
255           }
256         }
257       }
258     }
259     return true;
260   }
261
262 }