From 0e4983893a39906c5e884df57a77afc73da0c4a3 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Sat, 11 Apr 2009 01:31:12 +0000 Subject: [PATCH] changes --- .../Analysis/Locality/DiscoverConflicts.java | 376 ++++++++++++++++++ .../Analysis/Locality/LocalityAnalysis.java | 4 +- 2 files changed, 378 insertions(+), 2 deletions(-) create mode 100644 Robust/src/Analysis/Locality/DiscoverConflicts.java diff --git a/Robust/src/Analysis/Locality/DiscoverConflicts.java b/Robust/src/Analysis/Locality/DiscoverConflicts.java new file mode 100644 index 00000000..36da9d6b --- /dev/null +++ b/Robust/src/Analysis/Locality/DiscoverConflicts.java @@ -0,0 +1,376 @@ +package Analysis.Locality; + +import IR.Flat.*; +import java.util.Set; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Hashtable; +import IR.State; +import IR.TypeDescriptor; +import IR.MethodDescriptor; +import IR.FieldDescriptor; + +public DiscoverConflicts { + Set fields; + Set arrays; + LocalityAnalysis locality; + State state; + Hashtable> needsTR; + + public DiscoverConflicts(LocalityAnalysis locality, State state) { + this.locality=locality; + this.fields=new HashSet(); + this.arrays=new HashSet(); + this.needsTR=new Hashtable>(); + this.state=state; + transreadmap=new Hashtable>(); + srcmap=new Hashtable>(); + } + + public void doAnalysis() { + //Compute fields and arrays for all transactions + Set localityset=locality.getLocalityBindings(); + for(Iterator lb=localityset.iteratory();lb.hasNext();) { + computeModified(lb.next()); + } + expandTypes(); + //Compute set of nodes that need transread + Set localityset=locality.getLocalityBindings(); + for(Iterator lb=localityset.iteratory();lb.hasNext();) { + analyzeLocality(lb.next()); + } + } + public void expandTypes() { + FIX ARRAY...compute super/sub sets of each so we can do simple membership test + } + + 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); + } + } + } + return table; + } + + Hashtable> transreadmap; + Hashtable> srcmap; + + + public void analyzeLocality(LocalityBinding lb) { + Hashtable>> fnmap=computeTempSets(lb); + HashSet tfset=computeTranslationSet(lb, fnmap); + HashSet srctrans=new HashSet(); + transreadmap.put(lb, tfset); + srcmap.put(lb,srctrans); + + 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()) { + case FKind.FlatSetFieldNode: { + //definitely need to translate these + FlatSetFieldNode fsfn=(FlatSetFieldNode)fn; + Set tfpset=tmap.get(fsfn.getSrc()); + for(Iterator tfpit=tfpset.iterator();tfpit.hasNext();) { + TempFlatPair tfp=tfpit.nexT(); + if (tfset.contains(tfp)) { + srctrans.add(fsfn); + break; + } + } + break; + } + case FKind.FlatSetElementNode: { + //definitely need to translate these + FlatSetElementNode fsen=(FlatSetElementNode)fn; + Set tfpset=tmap.get(fsen.getSrc()); + for(Iterator tfpit=tfpset.iterator();tfpit.hasNext();) { + TempFlatPair tfp=tfpit.nexT(); + if (tfset.contains(tfp)) { + srctrans.add(fsfn); + break; + } + } + break; + } + default: + } + } + } + } + + HashSet computeTranslationSet(LocalityBinding lb, Hashtable>> fnmap) { + HashSet tfset=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) { + Hashtable> tmap=fnmap.get(fn); + switch(fn.kind()) { + case FKind.FlatElementNode: { + FlatElementNode fen=(FlatElementNode)fn; + if (arrays.contains(fen.getField())) { + //this could cause conflict...figure out conflict set + Set tfpset=tmap.get(fen.getSrc()); + 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()); + tfset.addAll(tfpset); + } + break; + } + case FKind.FlatSetFieldNode: { + //definitely need to translate these + FlatSetFieldNode fsfn=(FlatSetFieldNode)fn; + Set tfpset=tmap.get(fsfn.getDst()); + tfset.addAll(tfpset); + break; + } + case FKind.FlatSetElementNode: { + //definitely need to translate these + FlatSetElementNode fsen=(FlatSetElementNode)fn; + Set tfpset=tmap.get(fsen.getDst()); + tfset.addAll(tfpset); + break; + } + case FKind.FlatCall: //assume pessimistically that calls do bad things + case FKind.FlatReturn: { + TempDescriptor []readarray=fn.readsTemps(); + for(int i=0;i tfpset=tmap.get(rtmp); + tfset.addAll(tfpset); + } + break; + default: + //do nothing + } + } + } + } + return tfset; + } + + Hashtable>> computeTempSets(LocalityBinding lb) { + Hashtable> tmptofnset=new Hashtable, Set>(); + HashSet discovered=new HashSet(); + HashSet tovisit=new HashSet(); + MethodDescriptor md=lb.getMethod(); + FlatMethod fm=state.getMethodFlat(md); + Hashtable atomictable=locality.getAtomic(lb); + Hashtable> livetemps=locality.computeLiveTemps(fm); + 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))) { + //flatatomic enter node... see what we really need to transread + Set liveset=livetemps.get(fn); + ttofn=new Hashtable>(); + for(Iterator tmpit=liveset.iterator();tmpit.hasNext();) { + TempDescriptor tmp=tmpit.next(); + if (tmp.getType().isPtr()) { + HashSet fnset=new HashSet(); + fnset.add(new TempFlatPair(tmp, fn)); + ttofn.put(tmp, fnset); + } + } + } else { + ttofn=doMerge(fn, tmptofnset); + switch(fn.kind()) { + case FKind.FlatFieldNode: + case FKind.FlatElementNode: { + TempDescriptor[] writes=fn.writesTemps(); + for(int i=0;i set=new HashSet(); + set.add(new TempFlatPair(wtmp, fn)); + mtable.put(wtmp, set); + } + break; + } + case FKind.FlatOpNode: { + FlatOpNode fon=(FlatOpNode)fn; + if (fon.getOp().getOp()==Operation.ASSIGN&&fon.getDest().getType().isPtr()) { + mtable.put(fon.getDest(), new HashSet(mtable.get(fon.getLeft()))); + 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();) { + 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 fsfn=(FlatSetElementNode) fn; + arrays.add(fsen.getDst().getType()); + break; + default: + } + } + } + } + + Hashtable> computeOldTemps(LocalityBinding lb) { + Hashtable> fntooldtmp=new Hashtable>(); + HashSet discovered=new HashSet(); + HashSet tovisit=new HashSet(); + MethodDescriptor md=lb.getMethod(); + FlatMethod fm=state.getMethodFlat(md); + Hashtable atomictable=locality.getAtomic(lb); + Hashtable> livetemps=locality.computeLiveTemps(fm); + 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))) { + //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=fnotooldtmp.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&&fn.getDest().getType().isPtr()) { + if (oldtemps.contains(fn.getLeft())) + oldtemps.add(fn.getDest()); + else + oldtemps.remove(fn.getDest()); + break; + } + } + default: + { + TempDescriptor[] writes=fn.writesTemps(); + for(int i=0;i> computeLiveTemps(FlatMethod fm) { + + Hashtable> computeLiveTemps(FlatMethod fm) { Hashtable> nodetotemps=new Hashtable>(); Set toprocess=fm.getNodeSet(); -- 2.34.1