changes
authorbdemsky <bdemsky>
Mon, 13 Apr 2009 07:54:24 +0000 (07:54 +0000)
committerbdemsky <bdemsky>
Mon, 13 Apr 2009 07:54:24 +0000 (07:54 +0000)
Robust/src/Analysis/Locality/DiscoverConflicts.java
Robust/src/IR/Flat/BuildCode.java
Robust/src/IR/Flat/FlatMethod.java
Robust/src/Main/Main.java

index b3444de6cb00fcbe602719de5eee9716622a1e6f..cdb7c7063a181638e82ac9721b271d20f633f3e7 100644 (file)
@@ -13,70 +13,81 @@ import IR.MethodDescriptor;
 import IR.FieldDescriptor;
 
 public class DiscoverConflicts {
-    Set<FieldDescriptor> fields;
-    Set<TypeDescriptor> arrays;
-    LocalityAnalysis locality;
-    State state;
-
-    public DiscoverConflicts(LocalityAnalysis locality, State state) {
-       this.locality=locality;
-       this.fields=new HashSet<FieldDescriptor>();
-       this.arrays=new HashSet<TypeDescriptor>();
-       this.state=state;
-       transreadmap=new Hashtable<LocalityBinding, Set<TempFlatPair>>();
-       srcmap=new Hashtable<LocalityBinding, Set<FlatNode>>();
-    }
+  Set<FieldDescriptor> fields;
+  Set<TypeDescriptor> arrays;
+  LocalityAnalysis locality;
+  State state;
+  Hashtable<LocalityBinding, Set<FlatNode>> treadmap;
+  Hashtable<LocalityBinding, Set<TempFlatPair>> transreadmap;
+  Hashtable<LocalityBinding, Set<FlatNode>> srcmap;
     
-    public void doAnalysis() {
-       //Compute fields and arrays for all transactions
-       Set<LocalityBinding> localityset=locality.getLocalityBindings();
-       for(Iterator<LocalityBinding> lb=localityset.iterator();lb.hasNext();) {
-           computeModified(lb.next());
-       }
-       expandTypes();
-       //Compute set of nodes that need transread
-       for(Iterator<LocalityBinding> lb=localityset.iterator();lb.hasNext();) {
-           analyzeLocality(lb.next());
-       }
+  public DiscoverConflicts(LocalityAnalysis locality, State state) {
+    this.locality=locality;
+    this.fields=new HashSet<FieldDescriptor>();
+    this.arrays=new HashSet<TypeDescriptor>();
+    this.state=state;
+    transreadmap=new Hashtable<LocalityBinding, Set<TempFlatPair>>();
+    treadmap=new Hashtable<LocalityBinding, Set<FlatNode>>();
+    srcmap=new Hashtable<LocalityBinding, Set<FlatNode>>();
+  }
+  
+  public void doAnalysis() {
+    //Compute fields and arrays for all transactions
+    Set<LocalityBinding> localityset=locality.getLocalityBindings();
+    for(Iterator<LocalityBinding> lb=localityset.iterator();lb.hasNext();) {
+      computeModified(lb.next());
     }
-    public void expandTypes() {
-      //FIX ARRAY...compute super/sub sets of each so we can do simple membership test
+    expandTypes();
+    //Compute set of nodes that need transread
+    for(Iterator<LocalityBinding> lb=localityset.iterator();lb.hasNext();) {
+      LocalityBinding l=lb.next();
+      analyzeLocality(l);
+      setNeedReadTrans(l);
     }
+  }
 
-    Hashtable<TempDescriptor, Set<TempFlatPair>> doMerge(FlatNode fn, Hashtable<FlatNode, Hashtable<TempDescriptor, Set<TempFlatPair>>> tmptofnset) {
-       Hashtable<TempDescriptor, Set<TempFlatPair>> table=new Hashtable<TempDescriptor, Set<TempFlatPair>>();
-       for(int i=0;i<fn.numPrev();i++) {
-           FlatNode fprev=fn.getPrev(i);
-           Hashtable<TempDescriptor, Set<TempFlatPair>> tabset=tmptofnset.get(fprev);
-           if (tabset!=null) {
-               for(Iterator<TempDescriptor> tmpit=tabset.keySet().iterator();tmpit.hasNext();) {
-                   TempDescriptor td=tmpit.next();
-                   Set<TempFlatPair> fnset=tabset.get(td);
-                   if (!table.containsKey(td))
-                       table.put(td, new HashSet<TempFlatPair>());
-                   table.get(td).addAll(fnset);
-               }
-           }
-       }
-       return table;
+  public void setNeedReadTrans(LocalityBinding lb) {
+    HashSet<FlatNode> set=new HashSet<FlatNode>();
+    for(Iterator<TempFlatPair> it=transreadmap.get(lb).iterator();it.hasNext();) {
+      TempFlatPair tfp=it.next();
+      set.add(tfp.f);
     }
+    treadmap.put(lb, set);
+  }
 
-    Hashtable<LocalityBinding, Set<TempFlatPair>> transreadmap;
-    Hashtable<LocalityBinding, Set<FlatNode>> srcmap;
-
-    public Set<FlatNode> getNeedSrcTrans(LocalityBinding lb) {
-      return srcmap.get(lb);
-    }
+  public void expandTypes() {
+    //FIX ARRAY...compute super/sub sets of each so we can do simple membership test
+  }
 
-    public Set<FlatNode> getNeedReadTrans(LocalityBinding lb) {
-      HashSet<FlatNode> set=new HashSet<FlatNode>();
-      for(Iterator<TempFlatPair> it=transreadmap.get(lb).iterator();it.hasNext();) {
-       TempFlatPair tfp=it.next();
-       set.add(tfp.f);
+  Hashtable<TempDescriptor, Set<TempFlatPair>> doMerge(FlatNode fn, Hashtable<FlatNode, Hashtable<TempDescriptor, Set<TempFlatPair>>> tmptofnset) {
+    Hashtable<TempDescriptor, Set<TempFlatPair>> table=new Hashtable<TempDescriptor, Set<TempFlatPair>>();
+    for(int i=0;i<fn.numPrev();i++) {
+      FlatNode fprev=fn.getPrev(i);
+      Hashtable<TempDescriptor, Set<TempFlatPair>> tabset=tmptofnset.get(fprev);
+      if (tabset!=null) {
+       for(Iterator<TempDescriptor> tmpit=tabset.keySet().iterator();tmpit.hasNext();) {
+         TempDescriptor td=tmpit.next();
+         Set<TempFlatPair> fnset=tabset.get(td);
+         if (!table.containsKey(td))
+           table.put(td, new HashSet<TempFlatPair>());
+         table.get(td).addAll(fnset);
+       }
       }
-      return set;
     }
+    return table;
+  }
+  
+  public Set<FlatNode> getNeedSrcTrans(LocalityBinding lb) {
+    return srcmap.get(lb);
+  }
 
+  public boolean getNeedSrcTrans(LocalityBinding lb, FlatNode fn) {
+    return srcmap.get(lb).contains(fn);
+  }
+
+  public boolean getNeedTrans(LocalityBinding lb, FlatNode fn) {
+    return treadmap.get(lb).contains(fn);
+  }
 
   private void analyzeLocality(LocalityBinding lb) {
     MethodDescriptor md=lb.getMethod();
@@ -96,12 +107,16 @@ public class DiscoverConflicts {
        case FKind.FlatSetFieldNode: { 
          //definitely need to translate these
          FlatSetFieldNode fsfn=(FlatSetFieldNode)fn;
+         if (!fsfn.getField().getType().isPtr())
+           break;
          Set<TempFlatPair> tfpset=tmap.get(fsfn.getSrc());
-         for(Iterator<TempFlatPair> tfpit=tfpset.iterator();tfpit.hasNext();) {
-           TempFlatPair tfp=tfpit.next();
-           if (tfset.contains(tfp)) {
-             srctrans.add(fsfn);
-             break;
+         if (tfpset!=null) {
+           for(Iterator<TempFlatPair> tfpit=tfpset.iterator();tfpit.hasNext();) {
+             TempFlatPair tfp=tfpit.next();
+             if (tfset.contains(tfp)) {
+               srctrans.add(fsfn);
+               break;
+             }
            }
          }
          break;
@@ -109,12 +124,16 @@ public class DiscoverConflicts {
        case FKind.FlatSetElementNode: { 
          //definitely need to translate these
          FlatSetElementNode fsen=(FlatSetElementNode)fn;
+         if (!fsen.getSrc().getType().isPtr())
+           break;
          Set<TempFlatPair> tfpset=tmap.get(fsen.getSrc());
-         for(Iterator<TempFlatPair> tfpit=tfpset.iterator();tfpit.hasNext();) {
-           TempFlatPair tfp=tfpit.next();
-           if (tfset.contains(tfp)) {
-             srctrans.add(fsen);
-             break;
+         if (tfpset!=null) {
+           for(Iterator<TempFlatPair> tfpit=tfpset.iterator();tfpit.hasNext();) {
+             TempFlatPair tfp=tfpit.next();
+             if (tfset.contains(tfp)) {
+               srctrans.add(fsen);
+               break;
+             }
            }
          }
          break;
@@ -139,7 +158,8 @@ public class DiscoverConflicts {
          if (arrays.contains(fen.getSrc().getType())) {
            //this could cause conflict...figure out conflict set
            Set<TempFlatPair> tfpset=tmap.get(fen.getSrc());
-           tfset.addAll(tfpset);
+           if (tfpset!=null)
+             tfset.addAll(tfpset);
          }
          break;
        }
@@ -148,7 +168,8 @@ public class DiscoverConflicts {
          if (fields.contains(ffn.getField())) {
            //this could cause conflict...figure out conflict set
            Set<TempFlatPair> tfpset=tmap.get(ffn.getSrc());
-           tfset.addAll(tfpset);
+           if (tfpset!=null)
+             tfset.addAll(tfpset);
          }
          break;
        }
@@ -156,14 +177,16 @@ public class DiscoverConflicts {
          //definitely need to translate these
          FlatSetFieldNode fsfn=(FlatSetFieldNode)fn;
          Set<TempFlatPair> tfpset=tmap.get(fsfn.getDst());
-         tfset.addAll(tfpset);
+         if (tfpset!=null)
+           tfset.addAll(tfpset);
          break;
        }
        case FKind.FlatSetElementNode: { 
          //definitely need to translate these
          FlatSetElementNode fsen=(FlatSetElementNode)fn;
          Set<TempFlatPair> tfpset=tmap.get(fsen.getDst());
-         tfset.addAll(tfpset);
+         if (tfpset!=null)
+           tfset.addAll(tfpset);
          break;
        }
        case FKind.FlatCall: //assume pessimistically that calls do bad things
@@ -172,7 +195,8 @@ public class DiscoverConflicts {
          for(int i=0;i<readarray.length;i++) {
            TempDescriptor rtmp=readarray[i];
            Set<TempFlatPair> tfpset=tmap.get(rtmp);
-           tfset.addAll(tfpset);
+           if (tfpset!=null)
+             tfset.addAll(tfpset);
          }
          break;
        }
@@ -233,9 +257,21 @@ public class DiscoverConflicts {
            }
            break;
          }
+         case FKind.FlatCall:
+         case FKind.FlatMethod: {
+           TempDescriptor[] writes=fn.writesTemps();
+           for(int i=0;i<writes.length;i++) {
+             TempDescriptor wtmp=writes[i];
+             HashSet<TempFlatPair> set=new HashSet<TempFlatPair>();
+             set.add(new TempFlatPair(wtmp, fn));
+             ttofn.put(wtmp, set);
+           }
+           break;
+         }
          case FKind.FlatOpNode: {
            FlatOpNode fon=(FlatOpNode)fn;
-           if (fon.getOp().getOp()==Operation.ASSIGN&&fon.getDest().getType().isPtr()) {
+           if (fon.getOp().getOp()==Operation.ASSIGN&&fon.getDest().getType().isPtr()&&
+               ttofn.containsKey(fon.getLeft())) {
              ttofn.put(fon.getDest(), new HashSet<TempFlatPair>(ttofn.get(fon.getLeft())));
              break;
            }
index d2090b4c806268ec0b012ba43a71fb07ef6e5acc..d925e1c564d237f18c27060eda8b1a94f2b7a1c4 100644 (file)
@@ -17,6 +17,7 @@ import Analysis.TaskStateAnalysis.SafetyAnalysis;
 import Analysis.TaskStateAnalysis.TaskIndex;
 import Analysis.Locality.LocalityAnalysis;
 import Analysis.Locality.LocalityBinding;
+import Analysis.Locality.DiscoverConflicts;
 import Analysis.Prefetch.*;
 import Analysis.Loops.WriteBarrier;
 
@@ -52,6 +53,7 @@ public class BuildCode {
   HashSet<FlatSESEEnterNode> setSESEtoGen;
   boolean nonSESEpass=true;
   WriteBarrier wb;
+  DiscoverConflicts dc;
 
 
   public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, SafetyAnalysis sa, PrefetchAnalysis pa) {
@@ -81,6 +83,10 @@ public class BuildCode {
       this.backuptable=new Hashtable<LocalityBinding, Hashtable<TempDescriptor, TempDescriptor>>();
       this.wb=new WriteBarrier(locality, st);
     }
+    if (state.SINGLETM) {
+      this.dc=new DiscoverConflicts(locality, st);
+      dc.doAnalysis();
+    }
 
     setSESEtoGen = new HashSet<FlatSESEEnterNode>();
   }
@@ -2186,7 +2192,8 @@ public class BuildCode {
       String dst=generateTemp(fm, ffn.getDst(),lb);
 
       output.println(dst+"="+ src +"->"+field+ ";");
-      if (ffn.getField().getType().isPtr()&&locality.getAtomic(lb).get(ffn).intValue()>0) {
+      if (ffn.getField().getType().isPtr()&&locality.getAtomic(lb).get(ffn).intValue()>0&&
+         dc.getNeedTrans(lb, ffn)) {
        output.println("TRANSREAD("+dst+", "+dst+");");
       }
     } else if (state.DSM) {
@@ -2254,7 +2261,11 @@ public class BuildCode {
       String dst=generateTemp(fm,fsfn.getDst(),lb);
       if (srcptr&&!fsfn.getSrc().getType().isNull()) {
        output.println("{");
-       output.println("INTPTR srcoid=("+src+"!=NULL?((INTPTR)"+src+"->"+oidstr+"):0);");
+       if (dc.getNeedSrcTrans(lb, fsfn)) {
+         output.println("INTPTR srcoid=("+src+"!=NULL?((INTPTR)"+src+"->"+oidstr+"):0);");
+       } else {
+         output.println("INTPTR srcoid=(INTPTR)"+src+"->"+oidstr+";");
+       }
       }
       if (wb.needBarrier(fsfn))
        output.println("*((unsigned int *)&("+dst+"->___objstatus___))|=DIRTY;");
@@ -2348,7 +2359,8 @@ public class BuildCode {
       String dst=generateTemp(fm, fen.getDst(),lb);
       output.println(dst +"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex(),lb)+"];");
 
-      if (elementtype.isPtr()&&locality.getAtomic(lb).get(fen).intValue()>0) {
+      if (elementtype.isPtr()&&locality.getAtomic(lb).get(fen).intValue()>0&&
+         dc.getNeedTrans(lb, fen)) {
        output.println("TRANSREAD("+dst+", "+dst+");");
       }
     } else if (state.DSM) {
@@ -2403,7 +2415,11 @@ public class BuildCode {
       if (fsen.getSrc().getType().isPtr()&&!fsen.getSrc().getType().isNull()) {
        output.println("{");
        String src=generateTemp(fm, fsen.getSrc(), lb);
-       output.println("INTPTR srcoid=("+src+"!=NULL?((INTPTR)"+src+"->"+oidstr+"):0);");
+       if (dc.getNeedSrcTrans(lb, fsen)) {
+         output.println("INTPTR srcoid=("+src+"!=NULL?((INTPTR)"+src+"->"+oidstr+"):0);");
+       } else {
+         output.println("INTPTR srcoid=(INTPTR)"+src+"->"+oidstr+";");
+       }
        output.println("((INTPTR*)(((char *) &("+ generateTemp(fm,fsen.getDst(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fsen.getIndex(),lb)+"]=srcoid;");
        output.println("}");
       } else {
index 0cd5e7b2e71fff70cc56a16ff68dd65a6109fcab..cc60be51e43bde8e67bdca9e1f459df56e531db3 100644 (file)
@@ -33,6 +33,16 @@ public class FlatMethod extends FlatNode {
     } else {
       ret += task.toString();
     }
+    ret+="(";
+    boolean first=true;
+    for(int i=0;i<numParameters();i++) {
+      if (first) {
+       first=false;
+      } else
+       ret+=", ";
+      ret+=getParameter(i);
+    }
+    ret+=")";
     return ret;
   }
 
index 2b3d04e3f89e3ec200601860b7d7c5603afb91a2..cb8bf768501a1bda095d1cabb30f4c949a924c5f 100644 (file)
@@ -11,7 +11,6 @@ import java.util.Iterator;
 import java.util.Set;
 import java.util.Vector;
 
-import Analysis.Locality.DiscoverConflicts;
 import IR.Tree.ParseNode;
 import IR.Tree.BuildIR;
 import IR.Tree.SemanticCheck;
@@ -393,7 +392,6 @@ public class Main {
          pa=new PrefetchAnalysis(state, callgraph, tu, la);
        }
        LocalityAnalysis la=new LocalityAnalysis(state, callgraph, tu);
-       DiscoverConflicts dc=new DiscoverConflicts(la, state);
        GenerateConversions gc=new GenerateConversions(la, state);
        BuildCode bc=new BuildCode(state, bf.getMap(), tu, la, pa);
        bc.buildCode();