X-Git-Url: http://plrg.eecs.uci.edu/git/?p=IRC.git;a=blobdiff_plain;f=Robust%2Fsrc%2FAnalysis%2FLoops%2FCopyPropagation.java;h=06cff5da07b7493018ff154e28c87b98d9cfd17e;hp=71c9e7ca96a472a60645dd5113b1030b790bea51;hb=b124b7bf09a5eed6e272119acba9cfc5a1374b60;hpb=168ebf8a2d7f942efb3d1b2c92cc69c5f6f51c3b diff --git a/Robust/src/Analysis/Loops/CopyPropagation.java b/Robust/src/Analysis/Loops/CopyPropagation.java index 71c9e7ca..06cff5da 100644 --- a/Robust/src/Analysis/Loops/CopyPropagation.java +++ b/Robust/src/Analysis/Loops/CopyPropagation.java @@ -6,6 +6,7 @@ import java.util.Hashtable; import java.util.HashSet; import java.util.Set; import java.util.Map; +import Analysis.Liveness; public class CopyPropagation { public CopyPropagation() { @@ -17,105 +18,117 @@ public class CopyPropagation { boolean changed=false; TempDescriptor bogustd=new TempDescriptor("bogus"); do { + Hashtable> livetemps=Liveness.computeLiveTemps(fm,1000); + if(livetemps==null){ + System.out.println("Skipping CopyPropagation of "+fm.getMethod()+" due to size."); + return; + } changed=false; HashSet tovisit=new HashSet(); tovisit.add(fm); while(!tovisit.isEmpty()) { - FlatNode fn=(FlatNode) tovisit.iterator().next(); - tovisit.remove(fn); + FlatNode fn=(FlatNode) tovisit.iterator().next(); + tovisit.remove(fn); + Hashtable tab; + Set liveset=livetemps.get(fn); - Hashtable tab; - if (fn.numPrev()>=1&&table.containsKey(fn.getPrev(0))) - tab=new Hashtable(table.get(fn.getPrev(0))); - else - tab=new Hashtable(); - //Compute intersection + if (fn.numPrev()>=1&&table.containsKey(fn.getPrev(0))) { + tab=new Hashtable(); + for(Map.Entry entry:table.get(fn.getPrev(0)).entrySet()) { + if (liveset.contains(entry.getKey())) { + tab.put(entry.getKey(), entry.getValue()); + } + } + } else + tab=new Hashtable(); + //Compute intersection - for(int i=1;i tp=table.get(fn.getPrev(i)); - if (tp==null) - continue; - for(Iterator tmpit=tp.entrySet().iterator();tmpit.hasNext();) { - Map.Entry t=(Map.Entry)tmpit.next(); - TempDescriptor tmp=(TempDescriptor)t.getKey(); - - if (!tab.containsKey(tmp)) - tab.put(tmp, tp.get(tmp)); - else if (tab.get(tmp)!=tp.get(tmp)) { - tab.put(tmp, bogustd); - } - } - } + for(int i=1; i tp=table.get(fn.getPrev(i)); + if (tp==null) + continue; + for(Iterator tmpit=tp.entrySet().iterator(); tmpit.hasNext(); ) { + Map.Entry t=(Map.Entry)tmpit.next(); + TempDescriptor tmp=(TempDescriptor)t.getKey(); + if (!liveset.contains(tmp)) + continue; + TempDescriptor dsttmp=tp.get(tmp); + if (!tab.containsKey(tmp)) { + tab.put(tmp, dsttmp); + } else if (tab.get(tmp)!=dsttmp) { + tab.put(tmp, bogustd); + } + } + } + + HashSet toremove=new HashSet(); + TempDescriptor[] writes=fn.writesTemps(); + for(int i=0; i tmpit=tab.keySet().iterator(); tmpit.hasNext(); ) { + TempDescriptor tmp2=tmpit.next(); + if (tmp==tab.get(tmp2)) + toremove.add(tmp2); + } + } - HashSet toremove=new HashSet(); - TempDescriptor[]writes=fn.writesTemps(); - for(int i=0;i tmpit=tab.keySet().iterator();tmpit.hasNext();) { - TempDescriptor tmp2=tmpit.next(); - if (tmp==tab.get(tmp2)) - toremove.add(tmp2); - } - } + for(Iterator tmpit=toremove.iterator(); tmpit.hasNext(); ) { + TempDescriptor tmp=tmpit.next(); + tab.put(tmp, bogustd); + } - for(Iterator tmpit=toremove.iterator();tmpit.hasNext();) { - TempDescriptor tmp=tmpit.next(); - tab.put(tmp, bogustd); - } - - if (fn.kind()==FKind.FlatOpNode) { - FlatOpNode fon=(FlatOpNode)fn; - if (fon.getOp().getOp()==Operation.ASSIGN) { - tab.put(fon.getDest(), fon.getLeft()); - } - } - if (!table.containsKey(fn)||!table.get(fn).equals(tab)) { - table.put(fn,tab); - changed=true; - for(int i=0;i nodeset=fm.getNodeSet(); - for(Iterator it=fm.getNodeSet().iterator();it.hasNext();) { - FlatNode fn=it.next(); - if (fn.numPrev()==0) - continue; + for(Iterator it=fm.getNodeSet().iterator(); it.hasNext(); ) { + FlatNode fn=it.next(); + if (fn.numPrev()==0) + continue; + + Hashtable tab=new Hashtable(); - Hashtable tab=new Hashtable(); - - for(int i=0;i tp=table.get(fn.getPrev(i)); + for(int i=0; i tp=table.get(fn.getPrev(i)); + for(Iterator tmpit=tp.entrySet().iterator(); tmpit.hasNext(); ) { + Map.Entry t=(Map.Entry)tmpit.next(); + TempDescriptor tmp=(TempDescriptor)t.getKey(); - for(Iterator tmpit=tp.entrySet().iterator();tmpit.hasNext();) { - Map.Entry t=(Map.Entry)tmpit.next(); - TempDescriptor tmp=(TempDescriptor)t.getKey(); - - if (!tab.containsKey(tmp)) - tab.put(tmp, tp.get(tmp)); - else if (tab.get(tmp)!=tp.get(tmp)) { - tab.put(tmp, bogustd); - } - } - } + if (!tab.containsKey(tmp)) + tab.put(tmp, tp.get(tmp)); + else if (tab.get(tmp)!=tp.get(tmp)) { + tab.put(tmp, bogustd); + } + } + } - TempMap tmap=null; - TempDescriptor[]reads=fn.readsTemps(); - for(int i=0;i