changes to handle fixed point analysis properly + bug fix.
[IRC.git] / Robust / src / Analysis / ReachingDefs.java
index 411017a7164c03c2cb0159b53ba25b56044df9fc..d0f3ebd288018cf1d5ae4ebaa5419c86240e90cd 100644 (file)
@@ -5,13 +5,23 @@ import java.util.HashSet;
 import java.util.Set;
 import java.util.Iterator;
 import java.util.Hashtable;
+import Analysis.Locality.*;
 
 public class ReachingDefs {
   /* This methods takes in a FlatMethod and returns a map from a
    * FlatNode to the set of live temps for that FlatNode.*/
 
-  public static Hashtable<FlatNode, Hashtable<TempDescriptor, Set<FlatNode>>> computeReachingDefs(FlatMethod fm, Hashtable<FlatNode, Set<TempDescriptor>> livemap) {
+  /* liveintoset if true computes the reaching defs into the node and if false computes the reaching defs out of the node. */
+
+  public static Hashtable<FlatNode, Hashtable<TempDescriptor, Set<FlatNode>>> computeReachingDefs(FlatMethod fm, Hashtable<FlatNode, Set<TempDescriptor>> livemap, boolean liveintoset) {
+    return computeReachingDefs(fm, livemap, liveintoset, null);
+  }
+
+  public static Hashtable<FlatNode, Hashtable<TempDescriptor, Set<FlatNode>>> computeReachingDefs(FlatMethod fm, Hashtable<FlatNode, Set<TempDescriptor>> livemap, boolean liveintoset, LocalityBinding lb) {
     Hashtable<FlatNode, Hashtable<TempDescriptor, Set<FlatNode>>> nodetotemps=new Hashtable<FlatNode, Hashtable<TempDescriptor,Set<FlatNode>>>();
+
+    Hashtable<FlatNode, Hashtable<TempDescriptor, Set<FlatNode>>> liveinto=liveintoset?new Hashtable<FlatNode, Hashtable<TempDescriptor,Set<FlatNode>>>():null;
+    
     
     Set<FlatNode> toprocess=fm.getNodeSet();
     
@@ -37,14 +47,20 @@ public class ReachingDefs {
          }
        }
       }
+
+      if (liveintoset) {
+       liveinto.put(fn, new Hashtable<TempDescriptor, Set<FlatNode>>(tempset));
+      }
       
-      TempDescriptor writes[]=fn.writesTemps();
-      for(int i=0;i<writes.length;i++) {
-       HashSet<FlatNode> s=new HashSet<FlatNode>();
-       s.add(fn);
-       tempset.put(writes[i],s);
+      if (lb==null||(!(fn instanceof FlatGlobalConvNode))||
+         ((FlatGlobalConvNode) fn).getLocality()==lb) {
+       TempDescriptor writes[]=fn.writesTemps();
+       for(int i=0;i<writes.length;i++) {
+         HashSet<FlatNode> s=new HashSet<FlatNode>();
+         s.add(fn);
+         tempset.put(writes[i],s);
+       }
       }
-
       if (!nodetotemps.containsKey(fn)||
           !nodetotemps.get(fn).equals(tempset)) {
        nodetotemps.put(fn, tempset);
@@ -52,7 +68,6 @@ public class ReachingDefs {
          toprocess.add(fn.getNext(i));
       }
     }
-    return nodetotemps;
+    return liveintoset?liveinto:nodetotemps;
   }
-  
 }
\ No newline at end of file