From 99ffd85befe79ccc53723ddb99b4511aaaebce54 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Mon, 6 Aug 2007 09:11:28 +0000 Subject: [PATCH] changes --- .../Locality/GenerateConversions.java | 202 ++++++++++++++++++ .../Analysis/Locality/LocalityAnalysis.java | 67 +++++- 2 files changed, 268 insertions(+), 1 deletion(-) create mode 100644 Robust/src/Analysis/Locality/GenerateConversions.java diff --git a/Robust/src/Analysis/Locality/GenerateConversions.java b/Robust/src/Analysis/Locality/GenerateConversions.java new file mode 100644 index 00000000..8585773b --- /dev/null +++ b/Robust/src/Analysis/Locality/GenerateConversions.java @@ -0,0 +1,202 @@ +package Analysis.Locality; +import IR.State; +import IR.Flat.*; +import java.util.*; +import IR.MethodDescriptor; + + +public class GenerateConversions { + LocalityAnalysis locality; + State state; + + /** Warning: This class modifies the code in place. */ + + public GenerateConversions(LocalityAnalysis la, State state) { + locality=la; + this.state=state; + doConversion(); + } + + private void doConversion() { + Set bindings=locality.getLocalityBindings(); + Iterator bindit=bindings.iterator(); + while(bindit.hasNext()) { + LocalityBinding lb=bindit.next(); + //Don't need to do conversion if it is already atomic + if (lb.isAtomic()) + continue; + converttoPtr(lb); + converttoOid(lb); + } + } + + /* At the end of an atomic block, we need to convert any global + * references that will be used again into OID's */ + + private void converttoOid(LocalityBinding lb) { + Hashtable atomictab=locality.getAtomic(lb); + Hashtable> temptab=locality.getNodeTempInfo(lb); + MethodDescriptor md=lb.getMethod(); + FlatMethod fm=state.getMethodFlat(md); + + Hashtable> nodetotnpair=new Hashtable>(); + Hashtable> nodetoconvs=new Hashtable>(); + + Set toprocess=fm.getNodeSet(); + + while(!toprocess.isEmpty()) { + FlatNode fn=toprocess.iterator().next(); + toprocess.remove(fn); + boolean isatomic=atomictab.get(fn).intValue()>0; + Hashtable nodetemptab=temptab.get(fn); + + List reads=Arrays.asList(fn.readsTemps()); + List writes=Arrays.asList(fn.readsTemps()); + + if (!isatomic&&fn.kind()==FKind.FlatAtomicExitNode + &&!nodetoconvs.containsKey(fn)) + nodetoconvs.put(fn, new HashSet()); + + + HashSet tempset=new HashSet(); + for(int i=0;i prevset=nodetotnpair.get(fnprev); + for(Iterator it=prevset.iterator();it.hasNext();) { + TempNodePair tnp=it.next(); + if (reads.contains(tnp.getTemp())&&tnp.getNode()!=null) { + //Value actually is read... + nodetoconvs.get(tnp.getNode()).add(tnp.getTemp()); + } + if (writes.contains(tnp.getTemp())) //value overwritten + continue; + if (!isatomic&&fn.kind()==FKind.FlatAtomicExitNode) { + //Create new node and tag it with this exit + if (tnp.getNode()==null) { + TempNodePair tnp2=new TempNodePair(tnp.getTemp()); + tnp2.setNode(fn); + tempset.add(tnp2); + } + } else + tempset.add(tnp); + } + } + if (isatomic) { + //if this is in an atomic block, record temps that are written to + + /* NOTE: If this compiler is changed to maintain + * OID/Ptr's in variables, then we need to use all + * global temps that could be read and not just the + * ones converted by globalconvnode*/ + + if (fn.kind()!=FKind.FlatGlobalConvNode|| + ((FlatGlobalConvNode)fn).getLocality()==lb) + //If globalconvnode, make sure we have the right locality + for(Iterator writeit=writes.iterator();writeit.hasNext();) { + TempDescriptor wrtmp=writeit.next(); + if (nodetemptab.get(wrtmp)==LocalityAnalysis.GLOBAL) { + TempNodePair tnp=new TempNodePair(wrtmp); + tempset.add(tnp); + } + } + } + if (!nodetotnpair.containsKey(fn)||!nodetotnpair.get(fn).equals(tempset)) { + //changes to set, so enqueue next nodes + nodetotnpair.put(fn, tempset); //update set + for(int i=0;i it=toprocess.iterator();it.hasNext();) { + FlatNode fn=it.next(); + if (atomictab.get(fn).intValue()==0&& + atomictab.get(fn.getPrev(0)).intValue()>0) { + //sanity check + assert(fn.kind()==FKind.FlatAtomicExitNode); + + //insert calls here... + Set tempset=nodetoconvs.get(fn); + for(Iterator tempit=tempset.iterator();tempit.hasNext();) { + FlatGlobalConvNode fgcn=new FlatGlobalConvNode(tempit.next(), lb, false); + atomictab.put(fgcn, atomictab.get(fn)); + temptab.put(fgcn, (Hashtable) temptab.get(fn).clone()); + for(int i=0;i> nodetotranstemps=new Hashtable>(); + Hashtable atomictab=locality.getAtomic(lb); + Hashtable> temptab=locality.getNodeTempInfo(lb); + MethodDescriptor md=lb.getMethod(); + FlatMethod fm=state.getMethodFlat(md); + Set toprocess=fm.getNodeSet(); + + while(!toprocess.isEmpty()) { + FlatNode fn=toprocess.iterator().next(); + toprocess.remove(fn); + + if (atomictab.get(fn).intValue()>0) { + //build set of transaction temps use by next nodes + HashSet transtemps=new HashSet(); + for(int i=0;i it=toprocess.iterator();it.hasNext();) { + FlatNode fn=it.next(); + if (atomictab.get(fn).intValue()>0&& + atomictab.get(fn.getPrev(0)).intValue()==0) { + //sanity check + assert(fn.kind()==FKind.FlatAtomicEnterNode); + + //insert calls here... + Set tempset=nodetotranstemps.get(fn); + for(Iterator tempit=tempset.iterator();tempit.hasNext();) { + FlatGlobalConvNode fgcn=new FlatGlobalConvNode(tempit.next(), lb, true); + atomictab.put(fgcn, atomictab.get(fn)); + temptab.put(fgcn, (Hashtable) temptab.get(fn).clone()); + fgcn.addNext(fn.getNext(0)); + fn.setNext(0, fgcn); + } + } + } + } +} diff --git a/Robust/src/Analysis/Locality/LocalityAnalysis.java b/Robust/src/Analysis/Locality/LocalityAnalysis.java index 28e2d34b..cfcbd184 100644 --- a/Robust/src/Analysis/Locality/LocalityAnalysis.java +++ b/Robust/src/Analysis/Locality/LocalityAnalysis.java @@ -20,7 +20,7 @@ public class LocalityAnalysis { Hashtable> dependence; Hashtable>> temptab; Hashtable> atomictab; - + Hashtable>> tempstosave; CallGraph callgraph; TypeUtil typeutil; @@ -38,9 +38,23 @@ public class LocalityAnalysis { this.atomictab=new Hashtable>(); this.lbtovisit=new Stack(); this.callgraph=callgraph; + this.tempstosave=new Hashtable>>(); + doAnalysis(); } + public Set getLocalityBindings() { + return discovered.keySet(); + } + + public Hashtable> getNodeTempInfo(LocalityBinding lb) { + return temptab.get(lb); + } + + public Hashtable getAtomic(LocalityBinding lb) { + return atomictab.get(lb); + } + private void doAnalysis() { computeLocalityBindings(); } @@ -363,4 +377,55 @@ public class LocalityAnalysis { int atomic=atomictable.get(fen).intValue(); atomictable.put(fen, new Integer(atomic-1)); } + + private Hashtable> computeLiveTemps(FlatMethod fm) { + Hashtable> nodetotemps=new Hashtable>(); + + Set toprocess=fm.getNodeSet(); + + while(!toprocess.isEmpty()) { + FlatNode fn=toprocess.iterator().next(); + toprocess.remove(fn); + boolean isatomic=atomictab.get(fn).intValue()>0; + + List reads=Arrays.asList(fn.readsTemps()); + List writes=Arrays.asList(fn.readsTemps()); + + HashSet tempset=new HashSet(); + for(int i=0;iflatatomicenternode->Set + */ + + private void computeTempstoCheckpoint(LocalityBinding lb) { + Hashtable atomictab=getAtomic(lb); + Hashtable> temptab=getNodeTempInfo(lb); + MethodDescriptor md=lb.getMethod(); + FlatMethod fm=state.getMethodFlat(md); + + Hashtable> nodetotemps=computeLiveTemps(md); + + + } } -- 2.34.1