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