X-Git-Url: http://plrg.eecs.uci.edu/git/?p=IRC.git;a=blobdiff_plain;f=Robust%2Fsrc%2FAnalysis%2FLocality%2FDiscoverConflicts.java;h=eb9aad85878fb0dccd0c354df5ca9c8b55e69dae;hp=f382143ce4d157de251b2812ef6f22c869585a4a;hb=b124b7bf09a5eed6e272119acba9cfc5a1374b60;hpb=42949358a3b6d574838d4d490d8c9eb0fb23a315 diff --git a/Robust/src/Analysis/Locality/DiscoverConflicts.java b/Robust/src/Analysis/Locality/DiscoverConflicts.java index f382143c..eb9aad85 100644 --- a/Robust/src/Analysis/Locality/DiscoverConflicts.java +++ b/Robust/src/Analysis/Locality/DiscoverConflicts.java @@ -11,6 +11,8 @@ import IR.Operation; import IR.TypeDescriptor; import IR.MethodDescriptor; import IR.FieldDescriptor; +import Analysis.Liveness; +import Analysis.Loops.GlobalFieldType; public class DiscoverConflicts { Set fields; @@ -19,15 +21,21 @@ public class DiscoverConflicts { State state; Hashtable> treadmap; Hashtable> transreadmap; + Hashtable> twritemap; + Hashtable> writemap; + Hashtable> getmap; + Hashtable> srcmap; Hashtable> leftsrcmap; Hashtable> rightsrcmap; TypeAnalysis typeanalysis; Hashtable>cannotdelaymap; Hashtable>>> lbtofnmap; + boolean inclusive=false; + boolean normalassign=false; + GlobalFieldType gft; - - public DiscoverConflicts(LocalityAnalysis locality, State state, TypeAnalysis typeanalysis) { + public DiscoverConflicts(LocalityAnalysis locality, State state, TypeAnalysis typeanalysis, GlobalFieldType gft) { this.locality=locality; this.fields=new HashSet(); this.arrays=new HashSet(); @@ -39,9 +47,15 @@ public class DiscoverConflicts { leftsrcmap=new Hashtable>(); rightsrcmap=new Hashtable>(); lbtofnmap=new Hashtable>>>(); + if (gft!=null) { + twritemap=new Hashtable>(); + writemap=new Hashtable>(); + } + getmap=new Hashtable>(); + this.gft=gft; } - public DiscoverConflicts(LocalityAnalysis locality, State state, TypeAnalysis typeanalysis, Hashtable> cannotdelaymap) { + public DiscoverConflicts(LocalityAnalysis locality, State state, TypeAnalysis typeanalysis, Hashtable> cannotdelaymap, boolean inclusive, boolean normalassign, GlobalFieldType gft) { this.locality=locality; this.fields=new HashSet(); this.arrays=new HashSet(); @@ -54,6 +68,14 @@ public class DiscoverConflicts { leftsrcmap=new Hashtable>(); rightsrcmap=new Hashtable>(); lbtofnmap=new Hashtable>>>(); + this.inclusive=inclusive; + this.normalassign=normalassign; + if (gft!=null) { + twritemap=new Hashtable>(); + writemap=new Hashtable>(); + } + getmap=new Hashtable>(); + this.gft=gft; } public Set getFields() { @@ -63,40 +85,80 @@ public class DiscoverConflicts { public Set getArrays() { return arrays; } - + public void doAnalysis() { //Compute fields and arrays for all transactions. Note that we //only look at changes to old objects Set localityset=locality.getLocalityBindings(); - for(Iterator lb=localityset.iterator();lb.hasNext();) { + for(Iterator lb=localityset.iterator(); lb.hasNext(); ) { computeModified(lb.next()); } expandTypes(); //Compute set of nodes that need transread - for(Iterator lb=localityset.iterator();lb.hasNext();) { + for(Iterator lb=localityset.iterator(); lb.hasNext(); ) { LocalityBinding l=lb.next(); analyzeLocality(l); - setNeedReadTrans(l); } } //Change flatnode/temp pairs to just flatnodes that need transactional reads - public void setNeedReadTrans(LocalityBinding lb) { + private void setNeedReadTrans(LocalityBinding lb) { HashSet set=new HashSet(); - for(Iterator it=transreadmap.get(lb).iterator();it.hasNext();) { + for(Iterator it=transreadmap.get(lb).iterator(); it.hasNext(); ) { TempFlatPair tfp=it.next(); set.add(tfp.f); } treadmap.put(lb, set); + if (gft!=null) { + //need to translate write map set + set=new HashSet(); + for(Iterator it=writemap.get(lb).iterator(); it.hasNext(); ) { + TempFlatPair tfp=it.next(); + set.add(tfp.f); + } + twritemap.put(lb, set); + } + } + + private void computeneedsarrayget(LocalityBinding lb, Hashtable>> fnmap) { + // Set gwriteset=(state.READSET&&gft!=null)?twritemap.get(lb):treadmap.get(lb); + if (state.READSET&&gft!=null) { + if (twritemap.get(lb).size()==0) { + getmap.put(lb, new HashSet()); + return; + } + } + + Set gwriteset=treadmap.get(lb); + FlatMethod fm=state.getMethodFlat(lb.getMethod()); + HashSet needsget=new HashSet(); + for(Iterator fnit=fm.getNodeSet().iterator(); fnit.hasNext(); ) { + FlatNode fn=fnit.next(); + Hashtable atomictable=locality.getAtomic(lb); + if (atomictable.get(fn).intValue()>0&&fn.kind()==FKind.FlatElementNode) { + FlatElementNode fen=(FlatElementNode)fn; + Set tfpset=fnmap.get(fen).get(fen.getSrc()); + if (tfpset!=null) { + for(Iterator tfpit=tfpset.iterator(); tfpit.hasNext(); ) { + TempFlatPair tfp=tfpit.next(); + if (gwriteset.contains(tfp.f)) { + needsget.add(fen); + break; + } + } + } + } + } + getmap.put(lb, needsget); } //We have a set of things we write to, figure out what things this //could effect. public void expandTypes() { Set expandedarrays=new HashSet(); - for(Iterator it=arrays.iterator();it.hasNext();) { + for(Iterator it=arrays.iterator(); it.hasNext(); ) { TypeDescriptor td=it.next(); expandedarrays.addAll(typeanalysis.expand(td)); } @@ -105,22 +167,22 @@ public class DiscoverConflicts { Hashtable> doMerge(FlatNode fn, Hashtable>> tmptofnset) { Hashtable> table=new Hashtable>(); - for(int i=0;i> tabset=tmptofnset.get(fprev); if (tabset!=null) { - for(Iterator tmpit=tabset.keySet().iterator();tmpit.hasNext();) { - TempDescriptor td=tmpit.next(); - Set fnset=tabset.get(td); - if (!table.containsKey(td)) - table.put(td, new HashSet()); - table.get(td).addAll(fnset); - } + for(Iterator tmpit=tabset.keySet().iterator(); tmpit.hasNext(); ) { + TempDescriptor td=tmpit.next(); + Set fnset=tabset.get(td); + if (!table.containsKey(td)) + table.put(td, new HashSet()); + table.get(td).addAll(fnset); + } } } return table; } - + public Set getNeedSrcTrans(LocalityBinding lb) { return srcmap.get(lb); } @@ -141,6 +203,18 @@ public class DiscoverConflicts { return treadmap.get(lb).contains(fn); } + public boolean getNeedGet(LocalityBinding lb, FlatNode fn) { + if (gft!=null) + return getmap.get(lb).contains(fn); + else throw new Error(); + } + + public boolean getNeedWriteTrans(LocalityBinding lb, FlatNode fn) { + if (gft!=null) + return twritemap.get(lb).contains(fn); + else throw new Error(); + } + public Hashtable>> getMap(LocalityBinding lb) { return lbtofnmap.get(lb); } @@ -148,9 +222,19 @@ public class DiscoverConflicts { private void analyzeLocality(LocalityBinding lb) { MethodDescriptor md=lb.getMethod(); FlatMethod fm=state.getMethodFlat(md); + + //Compute map from flatnode -> (temps -> source of value) Hashtable>> fnmap=computeTempSets(lb); lbtofnmap.put(lb,fnmap); - HashSet tfset=computeTranslationSet(lb, fm, fnmap); + HashSet writeset=null; + if (gft!=null) { + writeset=new HashSet(); + } + HashSet tfset=computeTranslationSet(lb, fm, fnmap, writeset); + if (gft!=null) { + writemap.put(lb, writeset); + } + HashSet srctrans=new HashSet(); HashSet leftsrctrans=new HashSet(); HashSet rightsrctrans=new HashSet(); @@ -160,119 +244,122 @@ public class DiscoverConflicts { rightsrcmap.put(lb,rightsrctrans); //compute writes that need translation on source - - for(Iterator fnit=fm.getNodeSet().iterator();fnit.hasNext();) { + for(Iterator fnit=fm.getNodeSet().iterator(); fnit.hasNext(); ) { FlatNode fn=fnit.next(); Hashtable atomictable=locality.getAtomic(lb); if (atomictable.get(fn).intValue()>0) { - Hashtable> tmap=fnmap.get(fn); - switch(fn.kind()) { - - //We might need to translate arguments to pointer comparison - - case FKind.FlatOpNode: { - FlatOpNode fon=(FlatOpNode)fn; - if (fon.getOp().getOp()==Operation.EQUAL|| - fon.getOp().getOp()==Operation.NOTEQUAL) { - if (!fon.getLeft().getType().isPtr()) - break; - Set lefttfpset=tmap.get(fon.getLeft()); - Set righttfpset=tmap.get(fon.getRight()); - //handle left operand - if (lefttfpset!=null) { - for(Iterator tfpit=lefttfpset.iterator();tfpit.hasNext();) { - TempFlatPair tfp=tfpit.next(); - if (tfset.contains(tfp)||outofscope(tfp)) { - leftsrctrans.add(fon); - break; - } - } - } - //handle right operand - if (righttfpset!=null) { - for(Iterator tfpit=righttfpset.iterator();tfpit.hasNext();) { - TempFlatPair tfp=tfpit.next(); - if (tfset.contains(tfp)||outofscope(tfp)) { - rightsrctrans.add(fon); - break; - } - } - } - } - break; - } - - case FKind.FlatGlobalConvNode: { - //need to translate these if the value we read from may be a - //shadow... check this by seeing if any of the values we - //may read are in the transread set or came from our caller - //or a method we called - - FlatGlobalConvNode fgcn=(FlatGlobalConvNode)fn; - if (fgcn.getLocality()!=lb|| - fgcn.getMakePtr()) - break; - - Set tfpset=tmap.get(fgcn.getSrc()); - - if (tfpset!=null) { - for(Iterator tfpit=tfpset.iterator();tfpit.hasNext();) { - TempFlatPair tfp=tfpit.next(); - if (tfset.contains(tfp)||outofscope(tfp)) { - srctrans.add(fgcn); - break; - } - } - } - break; - } - - case FKind.FlatSetFieldNode: { - //need to translate these if the value we read from may be a - //shadow... check this by seeing if any of the values we - //may read are in the transread set or came from our caller - //or a method we called - - FlatSetFieldNode fsfn=(FlatSetFieldNode)fn; - if (!fsfn.getField().getType().isPtr()) - break; - Set tfpset=tmap.get(fsfn.getSrc()); - if (tfpset!=null) { - for(Iterator tfpit=tfpset.iterator();tfpit.hasNext();) { - TempFlatPair tfp=tfpit.next(); - if (tfset.contains(tfp)||outofscope(tfp)) { - srctrans.add(fsfn); - break; - } - } - } - break; - } - case FKind.FlatSetElementNode: { - //need to translate these if the value we read from may be a - //shadow... check this by seeing if any of the values we - //may read are in the transread set or came from our caller - //or a method we called - - FlatSetElementNode fsen=(FlatSetElementNode)fn; - if (!fsen.getSrc().getType().isPtr()) - break; - Set tfpset=tmap.get(fsen.getSrc()); - if (tfpset!=null) { - for(Iterator tfpit=tfpset.iterator();tfpit.hasNext();) { - TempFlatPair tfp=tfpit.next(); - if (tfset.contains(tfp)||outofscope(tfp)) { - srctrans.add(fsen); - break; - } - } - } - break; - } - default: - } + Hashtable> tmap=fnmap.get(fn); + switch(fn.kind()) { + //We might need to translate arguments to pointer comparison + + case FKind.FlatOpNode: { + FlatOpNode fon=(FlatOpNode)fn; + if (fon.getOp().getOp()==Operation.EQUAL|| + fon.getOp().getOp()==Operation.NOTEQUAL) { + if (!fon.getLeft().getType().isPtr()) + break; + Set lefttfpset=tmap.get(fon.getLeft()); + Set righttfpset=tmap.get(fon.getRight()); + //handle left operand + if (lefttfpset!=null) { + for(Iterator tfpit=lefttfpset.iterator(); tfpit.hasNext(); ) { + TempFlatPair tfp=tfpit.next(); + if (tfset.contains(tfp)||outofscope(tfp)) { + leftsrctrans.add(fon); + break; + } + } + } + //handle right operand + if (righttfpset!=null) { + for(Iterator tfpit=righttfpset.iterator(); tfpit.hasNext(); ) { + TempFlatPair tfp=tfpit.next(); + if (tfset.contains(tfp)||outofscope(tfp)) { + rightsrctrans.add(fon); + break; + } + } + } + } + break; + } + + case FKind.FlatGlobalConvNode: { + //need to translate these if the value we read from may be a + //shadow... check this by seeing if any of the values we + //may read are in the transread set or came from our caller + //or a method we called + + FlatGlobalConvNode fgcn=(FlatGlobalConvNode)fn; + if (fgcn.getLocality()!=lb|| + fgcn.getMakePtr()) + break; + + Set tfpset=tmap.get(fgcn.getSrc()); + + if (tfpset!=null) { + for(Iterator tfpit=tfpset.iterator(); tfpit.hasNext(); ) { + TempFlatPair tfp=tfpit.next(); + if (tfset.contains(tfp)||outofscope(tfp)) { + srctrans.add(fgcn); + break; + } + } + } + break; + } + + case FKind.FlatSetFieldNode: { + //need to translate these if the value we read from may be a + //shadow... check this by seeing if any of the values we + //may read are in the transread set or came from our caller + //or a method we called + + FlatSetFieldNode fsfn=(FlatSetFieldNode)fn; + if (!fsfn.getField().getType().isPtr()) + break; + Set tfpset=tmap.get(fsfn.getSrc()); + if (tfpset!=null) { + for(Iterator tfpit=tfpset.iterator(); tfpit.hasNext(); ) { + TempFlatPair tfp=tfpit.next(); + if (tfset.contains(tfp)||outofscope(tfp)) { + srctrans.add(fsfn); + break; + } + } + } + break; + } + + case FKind.FlatSetElementNode: { + //need to translate these if the value we read from may be a + //shadow... check this by seeing if any of the values we + //may read are in the transread set or came from our caller + //or a method we called + + FlatSetElementNode fsen=(FlatSetElementNode)fn; + if (!fsen.getSrc().getType().isPtr()) + break; + Set tfpset=tmap.get(fsen.getSrc()); + if (tfpset!=null) { + for(Iterator tfpit=tfpset.iterator(); tfpit.hasNext(); ) { + TempFlatPair tfp=tfpit.next(); + if (tfset.contains(tfp)||outofscope(tfp)) { + srctrans.add(fsen); + break; + } + } + } + break; + } + + default: + } } } + //Update results + setNeedReadTrans(lb); + computeneedsarrayget(lb, fnmap); } public boolean outofscope(TempFlatPair tfp) { @@ -280,80 +367,190 @@ public class DiscoverConflicts { return fn.kind()==FKind.FlatCall||fn.kind()==FKind.FlatMethod; } + private void computeReadOnly(LocalityBinding lb, Hashtable> updatedtypemap, Hashtable> updatedfieldmap) { + //inside of transaction, try to convert rw access to ro access + MethodDescriptor md=lb.getMethod(); + FlatMethod fm=state.getMethodFlat(md); + Hashtable atomictable=locality.getAtomic(lb); + + HashSet toanalyze=new HashSet(); + toanalyze.addAll(fm.getNodeSet()); + + while(!toanalyze.isEmpty()) { + FlatNode fn=toanalyze.iterator().next(); + toanalyze.remove(fn); + HashSet updatetypeset=new HashSet(); + HashSet updatefieldset=new HashSet(); + + //Stop if we aren't in a transaction + if (atomictable.get(fn).intValue()==0) + continue; + + //Do merge of all exits + for(int i=0; i fields=gft.getFieldsAll(mdfc); + updatefieldset.addAll(fields); + + //get modified arrays + Set arrays=gft.getArraysAll(mdfc); + updatetypeset.addAll(typeanalysis.expandSet(arrays)); + break; + } + } + } + + if (!updatedtypemap.containsKey(fn)||!updatedfieldmap.containsKey(fn)|| + !updatedtypemap.get(fn).equals(updatetypeset)||!updatedfieldmap.get(fn).equals(updatefieldset)) { + updatedtypemap.put(fn, updatetypeset); + updatedfieldmap.put(fn, updatefieldset); + for(int i=0; i computeTranslationSet(LocalityBinding lb, FlatMethod fm, Hashtable>> fnmap) { + HashSet computeTranslationSet(LocalityBinding lb, FlatMethod fm, Hashtable>> fnmap, Set writeset) { HashSet tfset=new HashSet(); - for(Iterator fnit=fm.getNodeSet().iterator();fnit.hasNext();) { - FlatNode fn=fnit.next(); + //Compute maps from flatnodes -> sets of things that may be updated after this node + Hashtable> updatedtypemap=null; + Hashtable> updatedfieldmap=null; - //Check whether this node matters for delayed computation - if (cannotdelaymap!=null&&cannotdelaymap.containsKey(lb)&&!cannotdelaymap.get(lb).contains(fn)) - continue; + if (writeset!=null&&!lb.isAtomic()) { + updatedtypemap=new Hashtable>(); + updatedfieldmap=new Hashtable>(); + computeReadOnly(lb, updatedtypemap, updatedfieldmap); + } - Hashtable atomictable=locality.getAtomic(lb); + for(Iterator fnit=fm.getNodeSet().iterator(); fnit.hasNext(); ) { + FlatNode fn=fnit.next(); + //Check whether this node matters for cannot delayed computation + if (cannotdelaymap!=null&&cannotdelaymap.containsKey(lb)&&cannotdelaymap.get(lb).contains(fn)==inclusive) + continue; + Hashtable atomictable=locality.getAtomic(lb); if (atomictable.get(fn).intValue()>0) { - Hashtable> tmap=fnmap.get(fn); - switch(fn.kind()) { - case FKind.FlatElementNode: { - FlatElementNode fen=(FlatElementNode)fn; - if (arrays.contains(fen.getSrc().getType())) { - //this could cause conflict...figure out conflict set - Set tfpset=tmap.get(fen.getSrc()); - if (tfpset!=null) - tfset.addAll(tfpset); - } - break; - } - case FKind.FlatFieldNode: { - FlatFieldNode ffn=(FlatFieldNode)fn; - if (fields.contains(ffn.getField())) { - //this could cause conflict...figure out conflict set - Set tfpset=tmap.get(ffn.getSrc()); - if (tfpset!=null) - tfset.addAll(tfpset); - } - break; - } - case FKind.FlatSetFieldNode: { - //definitely need to translate these - FlatSetFieldNode fsfn=(FlatSetFieldNode)fn; - Set tfpset=tmap.get(fsfn.getDst()); - if (tfpset!=null) - tfset.addAll(tfpset); - break; - } - case FKind.FlatSetElementNode: { - //definitely need to translate these - FlatSetElementNode fsen=(FlatSetElementNode)fn; - Set tfpset=tmap.get(fsen.getDst()); - if (tfpset!=null) - tfset.addAll(tfpset); - break; - } - case FKind.FlatCall: //assume pessimistically that calls do bad things - case FKind.FlatReturnNode: { - TempDescriptor []readarray=fn.readsTemps(); - for(int i=0;i tfpset=tmap.get(rtmp); - if (tfpset!=null) - tfset.addAll(tfpset); - } - break; - } - default: - //do nothing - } + Hashtable> tmap=fnmap.get(fn); + switch(fn.kind()) { + case FKind.FlatElementNode: { + FlatElementNode fen=(FlatElementNode)fn; + if (arrays.contains(fen.getSrc().getType())) { + //this could cause conflict...figure out conflict set + Set tfpset=tmap.get(fen.getSrc()); + if (tfpset!=null) + tfset.addAll(tfpset); + } + if (updatedtypemap!=null&&updatedtypemap.get(fen).contains(fen.getSrc().getType())) { + //this could cause conflict...figure out conflict set + Set tfpset=tmap.get(fen.getSrc()); + if (tfpset!=null) + tfset.addAll(tfpset); + } + break; + } + + case FKind.FlatFieldNode: { + FlatFieldNode ffn=(FlatFieldNode)fn; + if (fields.contains(ffn.getField())) { + //this could cause conflict...figure out conflict set + Set tfpset=tmap.get(ffn.getSrc()); + if (tfpset!=null) + tfset.addAll(tfpset); + } + if (updatedfieldmap!=null&&updatedfieldmap.get(ffn).contains(ffn.getField())) { + //this could cause conflict...figure out conflict set + Set tfpset=tmap.get(ffn.getSrc()); + if (tfpset!=null) + tfset.addAll(tfpset); + } + break; + } + + case FKind.FlatSetFieldNode: { + //definitely need to translate these + FlatSetFieldNode fsfn=(FlatSetFieldNode)fn; + Set tfpset=tmap.get(fsfn.getDst()); + if (tfpset!=null) + tfset.addAll(tfpset); + if (writeset!=null) { + if (tfpset!=null) + writeset.addAll(tfpset); + } + break; + } + + case FKind.FlatSetElementNode: { + //definitely need to translate these + FlatSetElementNode fsen=(FlatSetElementNode)fn; + Set tfpset=tmap.get(fsen.getDst()); + if (tfpset!=null) + tfset.addAll(tfpset); + if (writeset!=null) { + if (tfpset!=null) + writeset.addAll(tfpset); + } + break; + } + + case FKind.FlatCall: //assume pessimistically that calls do bad things + case FKind.FlatReturnNode: { + TempDescriptor [] readarray=fn.readsTemps(); + for(int i=0; i tfpset=tmap.get(rtmp); + if (tfpset!=null) + tfset.addAll(tfpset); + if (writeset!=null) { + if (tfpset!=null) + writeset.addAll(tfpset); + } + } + break; + } + + default: + //do nothing + } } - } + } return tfset; } @@ -371,123 +568,152 @@ public class DiscoverConflicts { MethodDescriptor md=lb.getMethod(); FlatMethod fm=state.getMethodFlat(md); Hashtable atomictable=locality.getAtomic(lb); - Hashtable> livetemps=locality.computeLiveTemps(fm); + Hashtable> livetemps=Liveness.computeLiveTemps(fm,-1); tovisit.add(fm); discovered.add(fm); - + while(!tovisit.isEmpty()) { FlatNode fn=tovisit.iterator().next(); tovisit.remove(fn); - for(int i=0;i> ttofn=null; if (atomictable.get(fn).intValue()!=0) { - if ((fn.numPrev()>0)&&atomictable.get(fn.getPrev(0)).intValue()==0) { - //atomic node, start with new set - ttofn=new Hashtable>(); - } else { - ttofn=doMerge(fn, tmptofnset); - switch(fn.kind()) { - case FKind.FlatGlobalConvNode: { - FlatGlobalConvNode fgcn=(FlatGlobalConvNode)fn; - if (lb==fgcn.getLocality()&& - fgcn.getMakePtr()) { - TempDescriptor[] writes=fn.writesTemps(); - for(int i=0;i set=new HashSet(); - set.add(new TempFlatPair(wtmp, fn)); - ttofn.put(wtmp, set); - } - } - break; - } - case FKind.FlatFieldNode: - case FKind.FlatElementNode: { - TempDescriptor[] writes=fn.writesTemps(); - for(int i=0;i set=new HashSet(); - set.add(new TempFlatPair(wtmp, fn)); - ttofn.put(wtmp, set); - } - break; - } - case FKind.FlatCall: - case FKind.FlatMethod: { - TempDescriptor[] writes=fn.writesTemps(); - for(int i=0;i set=new HashSet(); - set.add(new TempFlatPair(wtmp, fn)); - ttofn.put(wtmp, set); - } - break; - } - case FKind.FlatOpNode: { - FlatOpNode fon=(FlatOpNode)fn; - if (fon.getOp().getOp()==Operation.ASSIGN&&fon.getDest().getType().isPtr()&& - ttofn.containsKey(fon.getLeft())) { - ttofn.put(fon.getDest(), new HashSet(ttofn.get(fon.getLeft()))); - break; - } - } - default: - //Do kill computation - TempDescriptor[] writes=fn.writesTemps(); - for(int i=0;i0)&&atomictable.get(fn.getPrev(0)).intValue()==0) { + //atomic node, start with new set + ttofn=new Hashtable>(); + } else { + ttofn=doMerge(fn, tmptofnset); + switch(fn.kind()) { + case FKind.FlatGlobalConvNode: { + FlatGlobalConvNode fgcn=(FlatGlobalConvNode)fn; + if (lb==fgcn.getLocality()&& + fgcn.getMakePtr()) { + TempDescriptor[] writes=fn.writesTemps(); + for(int i=0; i set=new HashSet(); + set.add(new TempFlatPair(wtmp, fn)); + ttofn.put(wtmp, set); + } + } + break; + } + + case FKind.FlatFieldNode: + case FKind.FlatElementNode: { + TempDescriptor[] writes=fn.writesTemps(); + for(int i=0; i set=new HashSet(); + set.add(new TempFlatPair(wtmp, fn)); + ttofn.put(wtmp, set); + } + break; + } + + case FKind.FlatCall: + case FKind.FlatMethod: { + TempDescriptor[] writes=fn.writesTemps(); + for(int i=0; i set=new HashSet(); + set.add(new TempFlatPair(wtmp, fn)); + ttofn.put(wtmp, set); + } + break; + } + + case FKind.FlatCastNode: + case FKind.FlatOpNode: + if (fn.kind()==FKind.FlatCastNode) { + FlatCastNode fcn=(FlatCastNode)fn; + if (fcn.getDst().getType().isPtr()) { + HashSet set=new HashSet(); + if (ttofn.containsKey(fcn.getSrc())) + set.addAll(ttofn.get(fcn.getSrc())); + if (normalassign) + set.add(new TempFlatPair(fcn.getDst(), fn)); + ttofn.put(fcn.getDst(), set); + break; + } + } else if (fn.kind()==FKind.FlatOpNode) { + FlatOpNode fon=(FlatOpNode)fn; + if (fon.getOp().getOp()==Operation.ASSIGN&&fon.getDest().getType().isPtr()) { + HashSet set=new HashSet(); + if (ttofn.containsKey(fon.getLeft())) + set.addAll(ttofn.get(fon.getLeft())); + if (normalassign) + set.add(new TempFlatPair(fon.getDest(), fn)); + ttofn.put(fon.getDest(), set); + break; + } + } + + default: + //Do kill computation + TempDescriptor[] writes=fn.writesTemps(); + for(int i=0; i> oldtemps=computeOldTemps(lb); - for(Iterator fnit=fm.getNodeSet().iterator();fnit.hasNext();) { + for(Iterator fnit=fm.getNodeSet().iterator(); fnit.hasNext(); ) { FlatNode fn=fnit.next(); Hashtable atomictable=locality.getAtomic(lb); if (atomictable.get(fn).intValue()>0) { - switch (fn.kind()) { - case FKind.FlatSetFieldNode: - FlatSetFieldNode fsfn=(FlatSetFieldNode) fn; - fields.add(fsfn.getField()); - break; - case FKind.FlatSetElementNode: - FlatSetElementNode fsen=(FlatSetElementNode) fn; - arrays.add(fsen.getDst().getType()); - break; - default: - } + Set oldtemp=oldtemps.get(fn); + switch (fn.kind()) { + case FKind.FlatSetFieldNode: + FlatSetFieldNode fsfn=(FlatSetFieldNode) fn; + if (oldtemp.contains(fsfn.getDst())) + fields.add(fsfn.getField()); + break; + + case FKind.FlatSetElementNode: + FlatSetElementNode fsen=(FlatSetElementNode) fn; + if (oldtemp.contains(fsen.getDst())) + arrays.add(fsen.getDst().getType()); + break; + + default: + } } } } - + //Returns a table that maps a flatnode to a set of temporaries //This set of temporaries is old (meaning they may point to object @@ -500,77 +726,90 @@ public class DiscoverConflicts { MethodDescriptor md=lb.getMethod(); FlatMethod fm=state.getMethodFlat(md); Hashtable atomictable=locality.getAtomic(lb); - Hashtable> livetemps=locality.computeLiveTemps(fm); + Hashtable> livetemps=Liveness.computeLiveTemps(fm,-1); tovisit.add(fm); discovered.add(fm); - + while(!tovisit.isEmpty()) { FlatNode fn=tovisit.iterator().next(); tovisit.remove(fn); - for(int i=0;i oldtemps=null; if (atomictable.get(fn).intValue()!=0) { - if ((fn.numPrev()>0)&&atomictable.get(fn.getPrev(0)).intValue()==0) { - //Everything live is old - Set lives=livetemps.get(fn); - oldtemps=new HashSet(); - - for(Iterator it=lives.iterator();it.hasNext();) { - TempDescriptor tmp=it.next(); - if (tmp.getType().isPtr()) { - oldtemps.add(tmp); - } - } - } else { - oldtemps=new HashSet(); - //Compute union of old temporaries - for(int i=0;i pset=fntooldtmp.get(fn.getPrev(i)); - if (pset!=null) - oldtemps.addAll(pset); - } - - switch (fn.kind()) { - case FKind.FlatNew: - oldtemps.removeAll(Arrays.asList(fn.readsTemps())); - break; - case FKind.FlatOpNode: { - FlatOpNode fon=(FlatOpNode)fn; - if (fon.getOp().getOp()==Operation.ASSIGN&&fon.getDest().getType().isPtr()) { - if (oldtemps.contains(fon.getLeft())) - oldtemps.add(fon.getDest()); - else - oldtemps.remove(fon.getDest()); - break; - } - } - default: { - TempDescriptor[] writes=fn.writesTemps(); - for(int i=0;i0)&&atomictable.get(fn.getPrev(0)).intValue()==0) { + //Everything live is old + Set lives=livetemps.get(fn); + oldtemps=new HashSet(); + + for(Iterator it=lives.iterator(); it.hasNext(); ) { + TempDescriptor tmp=it.next(); + if (tmp.getType().isPtr()) { + oldtemps.add(tmp); + } + } + } else { + oldtemps=new HashSet(); + //Compute union of old temporaries + for(int i=0; i pset=fntooldtmp.get(fn.getPrev(i)); + if (pset!=null) + oldtemps.addAll(pset); + } + + switch (fn.kind()) { + case FKind.FlatNew: + oldtemps.removeAll(Arrays.asList(fn.readsTemps())); + break; + + case FKind.FlatOpNode: + case FKind.FlatCastNode: + if (fn.kind()==FKind.FlatCastNode) { + FlatCastNode fcn=(FlatCastNode)fn; + if (fcn.getDst().getType().isPtr()) { + if (oldtemps.contains(fcn.getSrc())) + oldtemps.add(fcn.getDst()); + else + oldtemps.remove(fcn.getDst()); + break; + } + } else if (fn.kind()==FKind.FlatOpNode) { + FlatOpNode fon=(FlatOpNode)fn; + if (fon.getOp().getOp()==Operation.ASSIGN&&fon.getDest().getType().isPtr()) { + if (oldtemps.contains(fon.getLeft())) + oldtemps.add(fon.getDest()); + else + oldtemps.remove(fon.getDest()); + break; + } + } + + default: { + TempDescriptor[] writes=fn.writesTemps(); + for(int i=0; i