From: bdemsky Date: Sun, 5 Apr 2009 04:52:04 +0000 (+0000) Subject: new write barrier class X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=16a7e2061d5733b022d1bf7780bc081938b0da4c;p=IRC.git new write barrier class fixed many bugs --- diff --git a/Robust/src/Analysis/Loops/CSE.java b/Robust/src/Analysis/Loops/CSE.java index 76adcd85..b98b4f09 100644 --- a/Robust/src/Analysis/Loops/CSE.java +++ b/Robust/src/Analysis/Loops/CSE.java @@ -22,7 +22,6 @@ public class CSE { public void doAnalysis(FlatMethod fm) { Hashtable> availexpr=new Hashtable>(); - HashSet toprocess=new HashSet(); HashSet discovered=new HashSet(); toprocess.add(fm); @@ -47,19 +46,23 @@ public class CSE { } switch(fn.kind()) { + case FKind.FlatAtomicEnterNode: + { + killexpressions(tab, null, null, true); + } case FKind.FlatCall: { FlatCall fc=(FlatCall) fn; MethodDescriptor md=fc.getMethod(); Set fields=gft.getFields(md); Set arrays=gft.getArrays(md); - killexpressions(tab, fields, arrays); + killexpressions(tab, fields, arrays, gft.containsAtomic(md)); break; } case FKind.FlatOpNode: { FlatOpNode fon=(FlatOpNode) fn; - Expression e=new Expression(fon.getLeft(), fon.getRight(),fon.getOp()); + Expression e=new Expression(fon.getLeft(), fon.getRight(), fon.getOp()); tab.put(e, fon.getDest()); break; } @@ -68,7 +71,7 @@ public class CSE { FlatSetFieldNode fsfn=(FlatSetFieldNode)fn; Set fields=new HashSet(); fields.add(fsfn.getField()); - killexpressions(tab, fields, null); + killexpressions(tab, fields, null, false); Expression e=new Expression(fsfn.getDst(), fsfn.getField()); tab.put(e, fsfn.getSrc()); break; @@ -114,52 +117,59 @@ public class CSE { } } } + doOptimize(fm, availexpr); } public void doOptimize(FlatMethod fm, Hashtable> availexpr) { - for(Iterator it=fm.getNodeSet().iterator();it.hasNext();) { - FlatNode fn=it.next(); - Hashtable tab=computeIntersection(fn, availexpr); - switch(fn.kind()) { - case FKind.FlatOpNode: - { - FlatOpNode fon=(FlatOpNode) fn; - Expression e=new Expression(fon.getLeft(), fon.getRight(),fon.getOp()); - if (tab.containsKey(e)) { - TempDescriptor t=tab.get(e); - FlatOpNode newfon=new FlatOpNode(fon.getDest(),t,null,new Operation(Operation.ASSIGN)); - fon.replace(newfon); - } - break; - } - case FKind.FlatFieldNode: - { - FlatFieldNode ffn=(FlatFieldNode)fn; - Expression e=new Expression(ffn.getSrc(), ffn.getField()); - if (tab.containsKey(e)) { - TempDescriptor t=tab.get(e); - FlatOpNode newfon=new FlatOpNode(ffn.getDst(),t,null,new Operation(Operation.ASSIGN)); - ffn.replace(newfon); - } - break; - } - case FKind.FlatElementNode: - { - FlatElementNode fen=(FlatElementNode)fn; - Expression e=new Expression(fen.getSrc(),fen.getIndex()); - if (tab.containsKey(e)) { - TempDescriptor t=tab.get(e); - FlatOpNode newfon=new FlatOpNode(fen.getDst(),t,null,new Operation(Operation.ASSIGN)); - fen.replace(newfon); - } - break; - } - default: + Hashtable replacetable=new Hashtable(); + for(Iterator it=fm.getNodeSet().iterator();it.hasNext();) { + FlatNode fn=it.next(); + Hashtable tab=computeIntersection(fn, availexpr); + switch(fn.kind()) { + case FKind.FlatOpNode: + { + FlatOpNode fon=(FlatOpNode) fn; + Expression e=new Expression(fon.getLeft(), fon.getRight(),fon.getOp()); + if (tab.containsKey(e)) { + TempDescriptor t=tab.get(e); + FlatNode newfon=new FlatOpNode(fon.getDest(),t,null,new Operation(Operation.ASSIGN)); + replacetable.put(fon,newfon); } + break; + } + case FKind.FlatFieldNode: + { + FlatFieldNode ffn=(FlatFieldNode)fn; + Expression e=new Expression(ffn.getSrc(), ffn.getField()); + if (tab.containsKey(e)) { + TempDescriptor t=tab.get(e); + FlatNode newfon=new FlatOpNode(ffn.getDst(),t,null,new Operation(Operation.ASSIGN)); + replacetable.put(ffn,newfon); + } + break; + } + case FKind.FlatElementNode: + { + FlatElementNode fen=(FlatElementNode)fn; + Expression e=new Expression(fen.getSrc(),fen.getIndex()); + if (tab.containsKey(e)) { + TempDescriptor t=tab.get(e); + FlatNode newfon=new FlatOpNode(fen.getDst(),t,null,new Operation(Operation.ASSIGN)); + replacetable.put(fen,newfon); + } + break; + } + default: } + } + for(Iterator it=replacetable.keySet().iterator();it.hasNext();) { + FlatNode fn=it.next(); + FlatNode newfn=replacetable.get(fn); + fn.replace(newfn); + } } - + public Hashtable computeIntersection(FlatNode fn, Hashtable> availexpr) { Hashtable tab=new Hashtable(); boolean first=true; @@ -168,9 +178,10 @@ public class CSE { for(int i=0;i table=availexpr.get(prev); @@ -185,11 +196,13 @@ public class CSE { return tab; } - public void killexpressions(Hashtable tab, Set fields, Set arrays) { + public void killexpressions(Hashtable tab, Set fields, Set arrays, boolean killall) { for(Iterator it=tab.entrySet().iterator();it.hasNext();) { Map.Entry m=(Map.Entry)it.next(); Expression e=(Expression)m.getKey(); - if (e.f!=null&&fields!=null&&fields.contains(e.f)) + if (killall&&(e.f!=null||e.a!=null)) + it.remove(); + else if (e.f!=null&&fields!=null&&fields.contains(e.f)) it.remove(); else if ((e.a!=null)&&(arrays!=null)) { for(Iterator arit=arrays.iterator();arit.hasNext();) { diff --git a/Robust/src/Analysis/Loops/DeadCode.java b/Robust/src/Analysis/Loops/DeadCode.java index 4df9eb48..d624fdd4 100644 --- a/Robust/src/Analysis/Loops/DeadCode.java +++ b/Robust/src/Analysis/Loops/DeadCode.java @@ -72,10 +72,9 @@ public class DeadCode { //get rid of useless nodes for(Iterator it=fm.getNodeSet().iterator();it.hasNext();) { FlatNode fn=it.next(); - if (!useful.contains(fn)) { + if (!useful.contains(fn)||isuseless(fn)) { //We have a useless node FlatNode fnnext=fn.getNext(0); - for(int i=0;i> fields; Hashtable> arrays; + HashSet containsAtomic; public GlobalFieldType(CallGraph cg, State st, MethodDescriptor root) { this.cg=cg; @@ -24,6 +25,7 @@ public class GlobalFieldType { this.root=root; this.fields=new Hashtable>(); this.arrays=new Hashtable>(); + this.containsAtomic=new HashSet(); doAnalysis(); } private void doAnalysis() { @@ -56,11 +58,19 @@ public class GlobalFieldType { changed=true; if (arrays.get(md).addAll(arrays.get(md2))) changed=true; + if (containsAtomic.contains(md2)) { + if (containsAtomic.add(md)) + changed=true; + } } } } } + public boolean containsAtomic(MethodDescriptor md) { + return containsAtomic.contains(md); + } + public Set getFields(MethodDescriptor md) { return fields.get(md); } @@ -82,6 +92,8 @@ public class GlobalFieldType { } else if (fn.kind()==FKind.FlatSetFieldNode) { FlatSetFieldNode fsfn=(FlatSetFieldNode)fn; fields.get(md).add(fsfn.getField()); + } else if (fn.kind()==FKind.FlatAtomicEnterNode) { + containsAtomic.add(md); } } } diff --git a/Robust/src/Analysis/Loops/WriteBarrier.java b/Robust/src/Analysis/Loops/WriteBarrier.java new file mode 100644 index 00000000..fd69784c --- /dev/null +++ b/Robust/src/Analysis/Loops/WriteBarrier.java @@ -0,0 +1,134 @@ +package Analysis.Loops; +import IR.Flat.*; +import Analysis.Locality.*; +import IR.Operation; +import IR.State; +import IR.MethodDescriptor; +import java.util.HashSet; +import java.util.Hashtable; +import java.util.Iterator; + +public class WriteBarrier { + /* This computes whether we actually need a write barrier. */ + LocalityAnalysis la; + State state; + public WriteBarrier(LocalityAnalysis la, State state) { + this.la=la; + this.state=state; + } + + public boolean needBarrier(FlatNode fn) { + HashSet nb=computeIntersection(fn); + switch(fn.kind()) { + case FKind.FlatSetElementNode: + { + FlatSetElementNode fsen=(FlatSetElementNode)fn; + return !nb.contains(fsen.getDst()); + } + case FKind.FlatSetFieldNode: + { + FlatSetFieldNode fsfn=(FlatSetFieldNode)fn; + return !nb.contains(fsfn.getDst()); + } + default: + return true; + } + } + + Hashtable> needbarrier; + + public void analyze(LocalityBinding lb) { + MethodDescriptor md=lb.getMethod(); + FlatMethod fm=state.getMethodFlat(md); + HashSet useful=new HashSet(); + HashSet toprocess=new HashSet(); + HashSet discovered=new HashSet(); + needbarrier=new Hashtable>(); + toprocess.add(fm); + discovered.add(fm); + Hashtable atomic=la.getAtomic(lb); + + while(!toprocess.isEmpty()) { + FlatNode fn=(FlatNode)toprocess.iterator().next(); + toprocess.remove(fn); + for(int i=0;i nb=computeIntersection(fn); + TempDescriptor[] writes=fn.writesTemps(); + for(int i=0;i0&& + atomic.get(fn.getPrev(0)).intValue()==0) { + nb=new HashSet(); + } + } + if (!needbarrier.containsKey(fn)|| + !needbarrier.get(fn).equals(nb)) { + for(int i=0;i computeIntersection(FlatNode fn) { + HashSet tab=new HashSet(); + boolean first=true; + for(int i=0;i hs=needbarrier.get(fprev); + if (hs!=null) { + if (first) { + tab.addAll(hs); + first=false; + } else { + //Intersect sets + for(Iterator it=tab.iterator();it.hasNext();) { + TempDescriptor t=it.next(); + if (!hs.contains(t)) + it.remove(); + } + } + } + } + return tab; + } +} \ No newline at end of file diff --git a/Robust/src/Analysis/Loops/localCSE.java b/Robust/src/Analysis/Loops/localCSE.java index 0d1b4e0d..155b8308 100644 --- a/Robust/src/Analysis/Loops/localCSE.java +++ b/Robust/src/Analysis/Loops/localCSE.java @@ -71,7 +71,7 @@ public class localCSE { Group g=getGroup(table,e); TempDescriptor td=getTemp(g); if (td!=null) { - FlatOpNode nfon=new FlatOpNode(fon.getDest(),td,null,new Operation(Operation.ASSIGN)); + FlatNode nfon=new FlatOpNode(fon.getDest(),td,null,new Operation(Operation.ASSIGN)); fn.replace(nfon); } g.set.add(dst); @@ -132,7 +132,7 @@ public class localCSE { dstf.set.add(src); HashSet fields=new HashSet(); fields.add(fsfn.getField()); - kill(table, fields, null); + kill(table, fields, null, false); table.put(src, dstf); break; } @@ -146,7 +146,7 @@ public class localCSE { dstf.set.add(src); HashSet arrays=new HashSet(); arrays.add(fsen.getDst().getType()); - kill(table, null, arrays); + kill(table, null, arrays, false); table.put(src, dstf); break; } @@ -156,7 +156,7 @@ public class localCSE { MethodDescriptor md=fc.getMethod(); Set fields=gft.getFields(md); Set arrays=gft.getArrays(md); - kill(table, fields, arrays); + kill(table, fields, arrays, gft.containsAtomic(md)); } default: { TempDescriptor[] writes=fn.writesTemps(); @@ -168,11 +168,15 @@ public class localCSE { } while(fn.numPrev()==1); } } - public void kill(Hashtable tab, Set fields, Set arrays) { + public void kill(Hashtable tab, Set fields, Set arrays, boolean isAtomic) { Set eset=tab.keySet(); for(Iterator it=eset.iterator();it.hasNext();) { LocalExpression e=it.next(); - if (e.td!=null) { + if (isAtomic&&(e.td!=null||e.f!=null)) { + Group g=tab.get(e); + g.set.remove(e); + it.remove(); + } else if (e.td!=null) { //have array TypeDescriptor artd=e.td; for(Iterator arit=arrays.iterator();arit.hasNext();) {