more analysis flexibility
authorbdemsky <bdemsky>
Tue, 30 Jun 2009 03:47:31 +0000 (03:47 +0000)
committerbdemsky <bdemsky>
Tue, 30 Jun 2009 03:47:31 +0000 (03:47 +0000)
Robust/src/Analysis/Liveness.java
Robust/src/Analysis/ReachingDefs.java

index 5e9c7d999e14c37912160f0c1d94497b8ccda17d..2b10f73945261569eda286197f4174a15169f7be 100644 (file)
@@ -4,6 +4,7 @@ import IR.Flat.*;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Hashtable;
 
@@ -41,4 +42,18 @@ public class Liveness {
     return nodetotemps;
   }
   
+  public static Hashtable<FlatNode, Set<TempDescriptor>> computeLiveOut(FlatMethod fm) {
+    Hashtable<FlatNode, Set<TempDescriptor>> liveinmap=computeLiveTemps(fm);
+    Hashtable<FlatNode, Set<TempDescriptor>> liveoutmap=new Hashtable<FlatNode, Set<TempDescriptor>>();
+    
+    for(Iterator<FlatNode> fnit=fm.getNodeSet().iterator(); fnit.hasNext();) {
+      FlatNode fn=fnit.next();
+      liveoutmap.put(fn, new HashSet<TempDescriptor>());
+      for(int i=0;i<fn.numNext();i++) {
+       FlatNode fn2=fn.getNext(i);
+       liveoutmap.get(fn).addAll(liveinmap.get(fn2));
+      }
+    }
+    return liveoutmap;
+  }
 }
\ No newline at end of file
index 411017a7164c03c2cb0159b53ba25b56044df9fc..f10f3f26e34e2b9d4a9889e088b3959cb35e77a2 100644 (file)
@@ -10,8 +10,13 @@ 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) {
     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,6 +42,10 @@ 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++) {
@@ -52,7 +61,7 @@ public class ReachingDefs {
          toprocess.add(fn.getNext(i));
       }
     }
-    return nodetotemps;
+    return liveintoset?liveinto:nodetotemps;
   }
   
 }
\ No newline at end of file