1) allow to set the maximum threshold for the liveness analysis. if threashold is...
[IRC.git] / Robust / src / Analysis / Loops / UseDef.java
index 7bf6b54c31f3d82e8628b34b9e446bcadd26e7dc..b58c1a4ce81153c29e0c41a592a74389384dc55a 100644 (file)
@@ -5,8 +5,9 @@ import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Set;
 import java.util.Iterator;
 import java.util.Hashtable;
 import java.util.Set;
 import java.util.Iterator;
+import Analysis.Liveness;
 
 
-public class UseDef{
+public class UseDef {
   Hashtable<TempFlatPair, Set<FlatNode>> defs;
   Hashtable<TempFlatPair, Set<FlatNode>> uses;
 
   Hashtable<TempFlatPair, Set<FlatNode>> defs;
   Hashtable<TempFlatPair, Set<FlatNode>> uses;
 
@@ -38,6 +39,7 @@ public class UseDef{
   public void analyze(FlatMethod fm) {
     Hashtable<FlatNode, Set<TempFlatPair>> tmp=new Hashtable<FlatNode, Set<TempFlatPair>>();
     HashSet<FlatNode> toanalyze=new HashSet<FlatNode>();
   public void analyze(FlatMethod fm) {
     Hashtable<FlatNode, Set<TempFlatPair>> tmp=new Hashtable<FlatNode, Set<TempFlatPair>>();
     HashSet<FlatNode> toanalyze=new HashSet<FlatNode>();
+    Hashtable<FlatNode, Set<TempDescriptor>> livemap=Liveness.computeLiveTemps(fm,-1);
     toanalyze.addAll(fm.getNodeSet());
     while(!toanalyze.isEmpty()) {
       FlatNode fn=toanalyze.iterator().next();
     toanalyze.addAll(fm.getNodeSet());
     while(!toanalyze.isEmpty()) {
       FlatNode fn=toanalyze.iterator().next();
@@ -45,55 +47,58 @@ public class UseDef{
 
       toanalyze.remove(fn);
       HashSet<TempFlatPair> s=new HashSet<TempFlatPair>();
 
       toanalyze.remove(fn);
       HashSet<TempFlatPair> s=new HashSet<TempFlatPair>();
-      for(int i=0;i<fn.numPrev();i++) {
-       FlatNode prev=fn.getPrev(i);
-       Set<TempFlatPair> prevs=tmp.get(prev);
-       if (prevs!=null) {
-         nexttfp:
-         for(Iterator<TempFlatPair> tfit=prevs.iterator();tfit.hasNext();) {
-           TempFlatPair tfp=tfit.next();
-           for(int j=0;j<fnwrites.length;j++) {
-             if (tfp.t==fnwrites[j])
-               continue nexttfp;
-           }
-           s.add(tfp);
-         }
-       }
-       for(int j=0;j<fnwrites.length;j++) {
-         TempFlatPair tfp=new TempFlatPair(fnwrites[j], fn);
-         s.add(tfp);
-       }
+      Set<TempDescriptor> liveset=livemap.get(fn);
+      for(int i=0; i<fn.numPrev(); i++) {
+        FlatNode prev=fn.getPrev(i);
+        Set<TempFlatPair> prevs=tmp.get(prev);
+        if (prevs!=null) {
+nexttfp:
+          for(Iterator<TempFlatPair> tfit=prevs.iterator(); tfit.hasNext(); ) {
+            TempFlatPair tfp=tfit.next();
+            if (!liveset.contains(tfp.t))
+              continue;
+            for(int j=0; j<fnwrites.length; j++) {
+              if (tfp.t==fnwrites[j])
+                continue nexttfp;
+            }
+            s.add(tfp);
+          }
+        }
+        for(int j=0; j<fnwrites.length; j++) {
+          TempFlatPair tfp=new TempFlatPair(fnwrites[j], fn);
+          s.add(tfp);
+        }
       }
       if (!tmp.containsKey(fn)||
       }
       if (!tmp.containsKey(fn)||
-         !tmp.get(fn).equals(s)) {
-       tmp.put(fn,s);
-       for(int i=0;i<fn.numNext();i++)
-         toanalyze.add(fn.getNext(i));
+          !tmp.get(fn).equals(s)) {
+        tmp.put(fn,s);
+        for(int i=0; i<fn.numNext(); i++)
+          toanalyze.add(fn.getNext(i));
       }
     }
     Set<FlatNode> fset=fm.getNodeSet();
     defs=new Hashtable<TempFlatPair, Set<FlatNode>>();
     uses=new Hashtable<TempFlatPair, Set<FlatNode>>();
       }
     }
     Set<FlatNode> fset=fm.getNodeSet();
     defs=new Hashtable<TempFlatPair, Set<FlatNode>>();
     uses=new Hashtable<TempFlatPair, Set<FlatNode>>();
-    for(Iterator<FlatNode> fnit=fset.iterator();fnit.hasNext();) {
+    for(Iterator<FlatNode> fnit=fset.iterator(); fnit.hasNext(); ) {
       FlatNode fn=fnit.next();
       TempDescriptor[] fnreads=fn.readsTemps();
       Set<TempFlatPair> tfpset=tmp.get(fn);
       FlatNode fn=fnit.next();
       TempDescriptor[] fnreads=fn.readsTemps();
       Set<TempFlatPair> tfpset=tmp.get(fn);
-      
-      for(int i=0;i<fnreads.length;i++) {
-       TempDescriptor readt=fnreads[i];
-       for(Iterator<TempFlatPair> tfpit=tfpset.iterator();tfpit.hasNext();) {
-         TempFlatPair tfp=tfpit.next();
-         if (tfp.t==readt) {
-           //have use
-           if (!uses.containsKey(tfp))
-             uses.put(tfp,new HashSet<FlatNode>());
-           uses.get(tfp).add(fn);
-           TempFlatPair readtfp=new TempFlatPair(readt,fn);
-           if (!defs.containsKey(readtfp))
-             defs.put(readtfp,new HashSet<FlatNode>());
-           defs.get(readtfp).add(tfp.f);
-         }
-       }
+
+      for(int i=0; i<fnreads.length; i++) {
+        TempDescriptor readt=fnreads[i];
+        for(Iterator<TempFlatPair> tfpit=tfpset.iterator(); tfpit.hasNext(); ) {
+          TempFlatPair tfp=tfpit.next();
+          if (tfp.t==readt) {
+            //have use
+            if (!uses.containsKey(tfp))
+              uses.put(tfp,new HashSet<FlatNode>());
+            uses.get(tfp).add(fn);
+            TempFlatPair readtfp=new TempFlatPair(readt,fn);
+            if (!defs.containsKey(readtfp))
+              defs.put(readtfp,new HashSet<FlatNode>());
+            defs.get(readtfp).add(tfp.f);
+          }
+        }
       }
     }
   }
       }
     }
   }