- while(!tovisit.isEmpty()) {
- FlatNode fn=tovisit.iterator().next();
- tovisit.remove(fn);
- Hashtable<TempDescriptor, Integer> currtable=new Hashtable<TempDescriptor, Integer>();
- int atomicstate=0;
- for(int i=0;i<fn.numPrev();i++) {
- FlatNode prevnode=fn.getPrev(i);
- if (atomictable.containsKey(prevnode)) {
- atomicstate=atomictable.get(prevnode).intValue();
- }
- if (!temptable.containsKey(prevnode))
- continue;
- Hashtable<TempDescriptor, Integer> prevtable=temptable.get(prevnode);
- for(Iterator<TempDescriptor> tempit=prevtable.keySet().iterator();tempit.hasNext();) {
- TempDescriptor temp=tempit.next();
- Integer tmpint=prevtable.get(temp);
- Integer oldint=currtable.containsKey(temp)?currtable.get(temp):EITHER;
- Integer newint=merge(tmpint, oldint);
- currtable.put(temp, newint);
- }
- }
- atomictable.put(fn, atomicstate);
- // Process this node
- switch(fn.kind()) {
- case FKind.FlatAtomicEnterNode:
- processAtomicEnterNode((FlatAtomicEnterNode)fn, atomictable);
- break;
- case FKind.FlatAtomicExitNode:
- processAtomicExitNode((FlatAtomicExitNode)fn, atomictable);
- break;
- case FKind.FlatCall:
- processCallNode(lb, (FlatCall)fn, currtable, isAtomic(atomictable, fn));
- break;
- case FKind.FlatFieldNode:
- processFieldNode(lb, (FlatFieldNode)fn, isAtomic(atomictable, fn), currtable);
- break;
- case FKind.FlatSetFieldNode:
- processSetFieldNode(lb, (FlatSetFieldNode)fn, isAtomic(atomictable,fn), currtable);
- break;
- case FKind.FlatNew:
- processNew(lb, (FlatNew)fn, isAtomic(atomictable, fn), currtable);
- break;
- case FKind.FlatOpNode:
- processOpNode((FlatOpNode)fn, currtable);
- break;
- case FKind.FlatCastNode:
- processCastNode((FlatCastNode)fn, currtable);
- break;
- case FKind.FlatLiteralNode:
- processLiteralNode((FlatLiteralNode)fn, currtable);
- break;
- case FKind.FlatReturnNode:
- processReturnNode(lb, (FlatReturnNode)fn, currtable);
- break;
- case FKind.FlatSetElementNode:
- processSetElementNode(lb, (FlatSetElementNode)fn, currtable, isAtomic(atomictable, fn));
- break;
- case FKind.FlatElementNode:
- processElementNode(lb, (FlatElementNode)fn, currtable, isAtomic(atomictable, fn));
- break;
- case FKind.FlatCondBranch:
- case FKind.FlatBackEdge:
- case FKind.FlatNop:
- //No action needed for these
- break;
- case FKind.FlatFlagActionNode:
- case FKind.FlatCheckNode:
- case FKind.FlatTagDeclaration:
- throw new Error("Incompatible with tasks!");
- case FKind.FlatMethod:
- default:
- throw new Error();
- }
- Hashtable<TempDescriptor,Integer> oldtable=temptable.get(fn);
- if (oldtable==null||!oldtable.equals(currtable)) {
- // Update table for this node
- temptable.put(fn, currtable);
- for(int i=0;i<fn.numNext();i++) {
- tovisit.add(fn.getNext(i));
- }
- }
- }
+ /** This methods returns a hashtable for a given LocalityBinding
+ * that tells which temps needs to be saved for each
+ * AtomicEnterNode. */
+
+ public Hashtable<FlatAtomicEnterNode, Set<TempDescriptor>> getTemps(LocalityBinding lb) {
+ return tempstosave.get(lb);
+ }
+
+ public Set<TempDescriptor> getTempSet(LocalityBinding lb) {
+ HashSet<TempDescriptor> set=new HashSet<TempDescriptor>();
+ Hashtable<FlatAtomicEnterNode, Set<TempDescriptor>> table=getTemps(lb);
+ if (table!=null)
+ for(Iterator<FlatAtomicEnterNode> faenit=table.keySet().iterator(); faenit.hasNext();) {
+ FlatAtomicEnterNode faen=faenit.next();
+ set.addAll(table.get(faen));
+ }
+ return set;
+ }
+
+ private void doAnalysis() {
+ computeLocalityBindings();
+ computeTempstoSave();
+ cleanSets();
+ }
+
+ private void cleanSets() {
+ HashSet<LocalityBinding> lbset=new HashSet<LocalityBinding>();
+ Stack<LocalityBinding> lbstack=new Stack<LocalityBinding>();
+ lbstack.add(lbmain);
+ lbstack.add(lbrun);
+ lbset.add(lbmain);
+ lbset.add(lbrun);
+ while(!lbstack.isEmpty()) {
+ LocalityBinding lb=lbstack.pop();
+ if (calldep.containsKey(lb)) {
+ Set<LocalityBinding> set=new HashSet<LocalityBinding>();
+ set.addAll(calldep.get(lb));
+ set.removeAll(lbset);
+ lbstack.addAll(set);
+ lbset.addAll(set);
+ }