Fix tabbing.... Please fix your editors so they do tabbing correctly!!! (Spaces...
[IRC.git] / Robust / src / IR / Flat / FlatSESEEnterNode.java
1 package IR.Flat;
2 import java.util.HashSet;
3 import java.util.Hashtable;
4 import java.util.Set;
5 import java.util.Vector;
6 import java.util.Iterator;
7 import java.util.Collection;
8 import Analysis.OoOJava.VariableSourceToken;
9 import Analysis.OoOJava.SESEandAgePair;
10 import Analysis.OwnershipAnalysis.HeapRegionNode;
11 import IR.ClassDescriptor;
12 import IR.FieldDescriptor;
13 import IR.MethodDescriptor;
14 import IR.TypeDescriptor;
15 import IR.Tree.SESENode;
16
17 public class FlatSESEEnterNode extends FlatNode {
18
19   // SESE class identifiers should be numbered
20   // sequentially from 0 to 1-(total # SESE's)
21   private static int identifier=0;
22
23   private int id;
24   protected FlatSESEExitNode exit;
25   protected SESENode treeNode;
26
27   // a leaf tasks simply has no children, ever
28   protected static final int ISLEAF_UNINIT = 1;
29   protected static final int ISLEAF_FALSE  = 2;
30   protected static final int ISLEAF_TRUE   = 3;
31   protected int isLeafSESE;
32
33   // there is only one main sese that is implicit
34   // (spliced in by the compiler around whole program)
35   protected boolean isMainSESE;
36
37   // this is a useful static name for whichever task
38   // invoked the current local method context
39   protected boolean isCallerProxySESE;
40
41   // all children tasks, INCLUDING those that are reachable
42   // by calling methods
43   protected Set<FlatSESEEnterNode> children;
44
45   // all possible parents
46   protected Set<FlatSESEEnterNode> parents;
47
48   // sometimes it is useful to know the locally defined
49   // parent or children of an SESE for various analysis,
50   // and by local it is one SESE nested within another
51   // in a single method context
52   protected Set<FlatSESEEnterNode> localChildren;
53   protected FlatSESEEnterNode localParent;
54
55
56   protected Set<TempDescriptor> inVars;
57   protected Set<TempDescriptor> outVars;
58
59
60   // for in-vars, classify them by source type to drive
61   // code gen for issuing this task
62   protected Set<TempDescriptor> readyInVars;
63   protected Set<TempDescriptor> staticInVars;
64   protected Set<TempDescriptor> dynamicInVars;
65   protected Set<SESEandAgePair> staticInVarSrcs;
66   protected Hashtable<TempDescriptor, VariableSourceToken> staticInVar2src;
67
68   // for out-vars, classify them by source type to drive
69   // code gen for when this task exits: if the exiting task
70   // has to assume the values from any of its children, it needs
71   // to know how to acquire those values before it can truly exit
72   protected Set<TempDescriptor> readyOutVars;
73   protected Set<TempDescriptor> staticOutVars;
74   protected Set<TempDescriptor> dynamicOutVars;
75   protected Set<SESEandAgePair> staticOutVarSrcs;
76   protected Hashtable<TempDescriptor, VariableSourceToken> staticOutVar2src;
77
78
79
80   // get the oldest age of this task that other contexts
81   // have a static name for when tracking variables
82   protected Integer oldestAgeToTrack;
83
84
85   // a subset of the in-set variables that shouuld be traversed during
86   // the dynamic coarse grained conflict strategy, remember them here so
87   // buildcode can be dumb and just gen the traversals
88   protected Vector<TempDescriptor> inVarsForDynamicCoarseConflictResolution;
89
90
91   // scope info for this SESE
92   protected FlatMethod fmEnclosing;
93   protected MethodDescriptor mdEnclosing;
94   protected ClassDescriptor cdEnclosing;
95
96   // structures that allow SESE to appear as
97   // a normal method to code generation
98   protected FlatMethod fmBogus;
99   protected MethodDescriptor mdBogus;
100
101   // used during code generation to calculate an offset
102   // into the SESE-specific record, specifically to the
103   // first field in a sequence of pointers to other SESE
104   // records which is relevant to garbage collection
105   protected String firstDepRecField;
106   protected int numDepRecs;
107
108
109   public FlatSESEEnterNode(SESENode sn) {
110     this.id              = identifier++;
111     treeNode             = sn;
112     children             = new HashSet<FlatSESEEnterNode>();
113     parents              = new HashSet<FlatSESEEnterNode>();
114     localChildren        = new HashSet<FlatSESEEnterNode>();
115     localParent          = null;
116     inVars               = new HashSet<TempDescriptor>();
117     outVars              = new HashSet<TempDescriptor>();
118     readyInVars          = new HashSet<TempDescriptor>();
119     staticInVars         = new HashSet<TempDescriptor>();
120     dynamicInVars        = new HashSet<TempDescriptor>();
121     staticInVarSrcs      = new HashSet<SESEandAgePair>();
122     readyOutVars         = new HashSet<TempDescriptor>();
123     staticOutVars        = new HashSet<TempDescriptor>();
124     dynamicOutVars       = new HashSet<TempDescriptor>();
125     staticOutVarSrcs     = new HashSet<SESEandAgePair>();
126     oldestAgeToTrack     = new Integer(0);
127
128     staticInVar2src  = new Hashtable<TempDescriptor, VariableSourceToken>();
129     staticOutVar2src = new Hashtable<TempDescriptor, VariableSourceToken>();
130
131     inVarsForDynamicCoarseConflictResolution = new Vector<TempDescriptor>();
132
133
134     fmEnclosing = null;
135     mdEnclosing = null;
136     cdEnclosing = null;
137
138     isLeafSESE = ISLEAF_UNINIT;
139
140     isMainSESE        = false;
141     isCallerProxySESE = false;
142
143     firstDepRecField = null;
144     numDepRecs       = 0;
145   }
146
147   public void rewriteUse() {
148   }
149
150   public void rewriteDef() {
151   }
152
153   public void setFlatExit(FlatSESEExitNode fsexn) {
154     exit = fsexn;
155   }
156
157   public FlatSESEExitNode getFlatExit() {
158     return exit;
159   }
160
161   public void setIsMainSESE() {
162     isMainSESE = true;
163   }
164
165   public boolean getIsMainSESE() {
166     return isMainSESE;
167   }
168
169   public void setIsCallerProxySESE() {
170     isCallerProxySESE = true;
171   }
172
173   public boolean getIsCallerProxySESE() {
174     return isCallerProxySESE;
175   }
176
177   public int kind() {
178     return FKind.FlatSESEEnterNode;
179   }
180
181   public SESENode getTreeNode() {
182     return treeNode;
183   }
184
185   public int getIdentifier() {
186     return id;
187   }
188
189   public String getPrettyIdentifier() {
190     if(isCallerProxySESE) {
191       return "proxy";
192     }
193     if( treeNode != null && treeNode.getID() != null ) {
194       return treeNode.getID();
195     }
196     return ""+id;
197   }
198
199   public String toString() {
200     return "sese "+getPrettyIdentifier()+" enter";
201   }
202
203   public String toPrettyString() {
204     return "sese "+getPrettyIdentifier()+getIdentifier();
205   }
206
207
208   public void mustTrackAtLeastAge(Integer age) {
209     if( age > oldestAgeToTrack ) {
210       oldestAgeToTrack = new Integer(age);
211     }
212   }
213
214   public Integer getOldestAgeToTrack() {
215     return oldestAgeToTrack;
216   }
217
218
219   public void addParent(FlatSESEEnterNode parent) {
220     parents.add(parent);
221   }
222
223   public Set<FlatSESEEnterNode> getParents() {
224     return parents;
225   }
226
227   public void setLocalParent(FlatSESEEnterNode parent) {
228     localParent = parent;
229   }
230
231   public FlatSESEEnterNode getLocalParent() {
232     return localParent;
233   }
234
235   public void addChild(FlatSESEEnterNode child) {
236     children.add(child);
237   }
238
239   public void addChildren(Set<FlatSESEEnterNode> batch) {
240     children.addAll(batch);
241   }
242
243   public Set<FlatSESEEnterNode> getChildren() {
244     return children;
245   }
246
247   public void addLocalChild(FlatSESEEnterNode child) {
248     localChildren.add(child);
249   }
250
251   public Set<FlatSESEEnterNode> getLocalChildren() {
252     return localChildren;
253   }
254
255
256
257   public void addInVar(TempDescriptor td) {
258     if (!inVars.contains(td))
259       inVars.add(td);
260   }
261
262   public void addOutVar(TempDescriptor td) {
263     outVars.add(td);
264   }
265
266   public void addInVarSet(Set<TempDescriptor> s) {
267     inVars.addAll(s);
268   }
269
270   public void addOutVarSet(Set<TempDescriptor> s) {
271     outVars.addAll(s);
272   }
273
274   public Set<TempDescriptor> getInVarSet() {
275     return inVars;
276   }
277
278   Vector<TempDescriptor> vecinVars;
279   void buildvarVec() {
280     HashSet<TempDescriptor> paramset=new HashSet<TempDescriptor>();
281     paramset.addAll(inVars);
282     paramset.addAll(outVars);
283     vecinVars=new Vector<TempDescriptor>();
284     vecinVars.addAll(paramset);
285   }
286
287   public TempDescriptor getParameter(int i) {
288     if (vecinVars==null) {
289       buildvarVec();
290     }
291     return vecinVars.get(i);
292   }
293
294   public int numParameters() {
295     if (vecinVars==null) {
296       buildvarVec();
297     }
298     return vecinVars.size();
299   }
300
301   public Set<FlatNode> getNodeSet() {
302     HashSet<FlatNode> tovisit=new HashSet<FlatNode>();
303     HashSet<FlatNode> visited=new HashSet<FlatNode>();
304     tovisit.add(this);
305     while(!tovisit.isEmpty()) {
306       FlatNode fn=tovisit.iterator().next();
307       tovisit.remove(fn);
308       visited.add(fn);
309
310       if (fn!=exit) {
311         for(int i=0; i<fn.numNext(); i++) {
312           FlatNode nn=fn.getNext(i);
313           if (!visited.contains(nn))
314             tovisit.add(nn);
315         }
316       }
317     }
318     return visited;
319   }
320
321   public Set<TempDescriptor> getOutVarSet() {
322     return outVars;
323   }
324
325   public void addStaticInVarSrc(SESEandAgePair p) {
326     staticInVarSrcs.add(p);
327   }
328
329   public Set<SESEandAgePair> getStaticInVarSrcs() {
330     return staticInVarSrcs;
331   }
332
333   public void addReadyInVar(TempDescriptor td) {
334     readyInVars.add(td);
335   }
336
337   public Set<TempDescriptor> getReadyInVarSet() {
338     return readyInVars;
339   }
340
341   public void addStaticInVar(TempDescriptor td) {
342     staticInVars.add(td);
343   }
344
345   public Set<TempDescriptor> getStaticInVarSet() {
346     return staticInVars;
347   }
348
349   public void putStaticInVar2src(TempDescriptor staticInVar,
350                                  VariableSourceToken vst) {
351     staticInVar2src.put(staticInVar, vst);
352   }
353
354   public VariableSourceToken getStaticInVarSrc(TempDescriptor staticInVar) {
355     return staticInVar2src.get(staticInVar);
356   }
357
358   public void addDynamicInVar(TempDescriptor td) {
359     dynamicInVars.add(td);
360   }
361
362   public Set<TempDescriptor> getDynamicInVarSet() {
363     return dynamicInVars;
364   }
365
366
367
368   public void addReadyOutVar(TempDescriptor td) {
369     readyOutVars.add(td);
370   }
371
372   public Set<TempDescriptor> getReadyOutVarSet() {
373     return readyOutVars;
374   }
375
376   public void addStaticOutVarSrc(SESEandAgePair p) {
377     staticOutVarSrcs.add(p);
378   }
379
380   public Set<SESEandAgePair> getStaticOutVarSrcs() {
381     return staticOutVarSrcs;
382   }
383
384   public void addStaticOutVar(TempDescriptor td) {
385     staticOutVars.add(td);
386   }
387
388   public Set<TempDescriptor> getStaticOutVarSet() {
389     return staticOutVars;
390   }
391
392   public void putStaticOutVar2src(TempDescriptor staticOutVar,
393                                   VariableSourceToken vst) {
394     staticOutVar2src.put(staticOutVar, vst);
395   }
396
397   public VariableSourceToken getStaticOutVarSrc(TempDescriptor staticOutVar) {
398     return staticOutVar2src.get(staticOutVar);
399   }
400
401   public void addDynamicOutVar(TempDescriptor td) {
402     dynamicOutVars.add(td);
403   }
404
405   public Set<TempDescriptor> getDynamicOutVarSet() {
406     return dynamicOutVars;
407   }
408
409
410
411
412   public void setfmEnclosing(FlatMethod fm) {
413     fmEnclosing = fm;
414   }
415   public FlatMethod getfmEnclosing() {
416     return fmEnclosing;
417   }
418
419   public void setmdEnclosing(MethodDescriptor md) {
420     mdEnclosing = md;
421   }
422   public MethodDescriptor getmdEnclosing() {
423     return mdEnclosing;
424   }
425
426   public void setcdEnclosing(ClassDescriptor cd) {
427     cdEnclosing = cd;
428   }
429   public ClassDescriptor getcdEnclosing() {
430     return cdEnclosing;
431   }
432
433   public void setfmBogus(FlatMethod fm) {
434     fmBogus = fm;
435   }
436   public FlatMethod getfmBogus() {
437     return fmBogus;
438   }
439
440   public void setmdBogus(MethodDescriptor md) {
441     mdBogus = md;
442   }
443   public MethodDescriptor getmdBogus() {
444     return mdBogus;
445   }
446
447   public String getSESEmethodName() {
448     assert cdEnclosing != null;
449     assert mdBogus != null;
450
451     return
452       cdEnclosing.getSafeSymbol()+
453       mdBogus.getSafeSymbol()+
454       "_"+
455       mdBogus.getSafeMethodDescriptor();
456   }
457
458   public String getSESErecordName() {
459     assert cdEnclosing != null;
460     assert mdBogus != null;
461
462     return
463       "struct "+
464       cdEnclosing.getSafeSymbol()+
465       mdBogus.getSafeSymbol()+
466       "_"+
467       mdBogus.getSafeMethodDescriptor()+
468       "_SESErec";
469   }
470
471   public boolean equals(Object o) {
472     if( o == null ) {
473       return false;
474     }
475
476     if( !(o instanceof FlatSESEEnterNode) ) {
477       return false;
478     }
479
480     FlatSESEEnterNode fsen = (FlatSESEEnterNode) o;
481     return id == fsen.id;
482   }
483
484   public int hashCode() {
485     return 31*id;
486   }
487
488
489
490   public void setFirstDepRecField(String field) {
491     firstDepRecField = field;
492   }
493
494   public String getFirstDepRecField() {
495     return firstDepRecField;
496   }
497
498   public void incNumDepRecs() {
499     ++numDepRecs;
500   }
501
502   public int getNumDepRecs() {
503     return numDepRecs;
504   }
505
506   public Vector<TempDescriptor> getInVarsForDynamicCoarseConflictResolution() {
507     return inVarsForDynamicCoarseConflictResolution;
508   }
509
510   public void addInVarForDynamicCoarseConflictResolution(TempDescriptor inVar) {
511     if (!inVarsForDynamicCoarseConflictResolution.contains(inVar))
512       inVarsForDynamicCoarseConflictResolution.add(inVar);
513   }
514
515   public void setIsLeafSESE(boolean isLeaf) {
516     if( isLeaf ) {
517       isLeafSESE = ISLEAF_TRUE;
518     } else {
519       isLeafSESE = ISLEAF_FALSE;
520     }
521   }
522
523   public boolean getIsLeafSESE() {
524     if( isLeafSESE == ISLEAF_UNINIT ) {
525       throw new Error("isLeafSESE uninitialized");
526     }
527
528     return isLeafSESE == ISLEAF_TRUE;
529   }
530
531 }