From: adash Date: Wed, 31 Oct 2007 21:19:24 +0000 (+0000) Subject: bug fixes to handle propagation for FlatOpNode method for simple cases X-Git-Tag: preEdgeChange~404 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=86ac9703cf8ba9aa4d9f149751dce9f812ae499a;p=IRC.git bug fixes to handle propagation for FlatOpNode method for simple cases bug fixes for null exception for prefetch hashtable remove unnecessary print statements --- diff --git a/Robust/src/Analysis/Prefetch/PrefetchAnalysis.java b/Robust/src/Analysis/Prefetch/PrefetchAnalysis.java index c171eb1a..ef36272f 100644 --- a/Robust/src/Analysis/Prefetch/PrefetchAnalysis.java +++ b/Robust/src/Analysis/Prefetch/PrefetchAnalysis.java @@ -50,68 +50,19 @@ public class PrefetchAnalysis { /** This function calls analysis for every node in a method */ private void doFlatNodeAnalysis(FlatMethod fm) { tovisit = fm.getNodeSet(); //Flat nodes to process + Hashtable nodehash = new Hashtable(); + /* Create Empty Prefetch Sets for all flat nodes in the global hashtable */ while(!tovisit.isEmpty()) { FlatNode fn = (FlatNode)tovisit.iterator().next(); - /* Generate self node prefetch pairs */ - doNodePrefetch(fn); - /* Generate prefetch pairs after the child node analysis */ - boolean curr_modified = doNodeChildPrefetch(fn); + prefetch_hash.put(fn, nodehash); tovisit.remove(fn); } - } - - /** - * This function generates initial prefetch pair for a Flat node that is of the - * following kind FlatFieldNode, FlatElementNode, FlatSetFieldNode or FlatSetElementNode - * */ - private void doNodePrefetch(FlatNode fn) { - Hashtable nodehash = new Hashtable(); - switch(fn.kind()) { - case FKind.FlatFieldNode: - FlatFieldNode currffn = (FlatFieldNode) fn; - FieldDescriptor currffn_field = currffn.getField(); - TempDescriptor currffn_src = currffn.getSrc(); - if (currffn_field.getType().isPtr()) { - Boolean b = new Boolean(false); - PrefetchPair pp = new PrefetchPair(currffn_src, (Descriptor) currffn_field, b); - Float prob = new Float((float)1.0); - nodehash.put(pp, prob); - prefetch_hash.put(fn, nodehash); - } - break; - case FKind.FlatElementNode: - FlatElementNode currfen = (FlatElementNode) fn; - TempDescriptor currfen_index = currfen.getIndex(); - TempDescriptor currfen_src = currfen.getSrc(); - if(currfen.getDst().getType().isPtr()) { - PrefetchPair pp = new PrefetchPair(currfen_src, (Descriptor) currfen_index, true); - Float prob = new Float((float)1.0); - nodehash.put(pp, prob); - prefetch_hash.put(fn, nodehash); - } - break; - case FKind.FlatSetFieldNode: - FlatSetFieldNode currfsfn = (FlatSetFieldNode) fn; - TempDescriptor currfsfn_src = currfsfn.getSrc(); - if (currfsfn_src.getType().isPtr()) { - PrefetchPair pp = new PrefetchPair(currfsfn_src); - Float prob = new Float((float)1.0); - nodehash.put(pp, prob); - prefetch_hash.put(fn, nodehash); - } - break; - case FKind.FlatSetElementNode: - FlatSetElementNode currfsen = (FlatSetElementNode) fn; - TempDescriptor currfsen_src = currfsen.getSrc(); - if (currfsen_src.getType().isPtr()) { - PrefetchPair pp = new PrefetchPair(currfsen_src); - Float prob = new Float((float)1.0); - nodehash.put(pp, prob); - prefetch_hash.put(fn, nodehash); - } - break; - default: - break; + tovisit = fm.getNodeSet(); //Flat nodes to process + while(!tovisit.isEmpty()) { + FlatNode fn = (FlatNode)tovisit.iterator().next(); + /* Generate prefetch pairs after the child node analysis */ + boolean curr_modified = doChildNodeAnalysis(fn); + tovisit.remove(fn); } } @@ -121,8 +72,8 @@ public class PrefetchAnalysis { * returns true: if the prefetch set has changed since last time the node was analysed * returns false : otherwise */ - private boolean doNodeChildPrefetch(FlatNode curr) { - boolean ppSetHasChanged = false; + private boolean doChildNodeAnalysis(FlatNode curr) { + boolean pSetHasChanged = false; Hashtable child_hash = new Hashtable(); for (int i = 0; i < curr.numNext(); i++) { FlatNode child_node = curr.getNext(i); @@ -131,73 +82,49 @@ public class PrefetchAnalysis { } switch(curr.kind()) { case FKind.FlatFieldNode: - if(prefetch_hash.containsKey(curr)) { - processFlatFieldNode(curr, child_hash); - } else { - prefetch_hash.put(curr, child_hash); - } + processFlatFieldNode(curr, child_hash); break; case FKind.FlatElementNode: - if(prefetch_hash.containsKey(curr)) { - processFlatElementNode(curr, child_hash); - } else { - prefetch_hash.put(curr, child_hash); - } - break; - case FKind.FlatCall: - //processFlatCallNode(); + processFlatElementNode(curr, child_hash); break; case FKind.FlatCondBranch: //processFlatCondBranchNode(); break; case FKind.FlatNew: - //processFlatNewNode(); + //processFlatNewNode(curr, child_hash); break; case FKind.FlatOpNode: - //processFlatOpNode(); + processFlatOpNode(curr, child_hash); break; case FKind.FlatSetElementNode: - //processFlatSetElementNode(); + processFlatSetElementNode(curr, child_hash); break; case FKind.FlatSetFieldNode: - //processFlatSetFieldNode(); + processFlatSetFieldNode(curr, child_hash); break; default: /*If FlatNode is not concerned with the prefetch set of its Child then propagate * prefetches up the FlatNode*/ - //TODO make this a new method - if(prefetch_hash.containsKey(curr)) { - Hashtable currcopy = (Hashtable)prefetch_hash.get(curr).clone(); - Hashtable tocompare = new Hashtable(); - Enumeration e = currcopy.keys(); - while (e.hasMoreElements()) { - PrefetchPair pp = (PrefetchPair) e.nextElement(); - if (child_hash.contains(pp)) { - Float cprob = child_hash.get(pp); - Float fprob = currcopy.get(pp); - // TODO fix this - Float newprob = cprob.floatValue() * fprob.floatValue(); - tocompare.put(pp, newprob); - child_hash.remove(pp); - } else { - tocompare.put(pp, currcopy.get(pp)); - } - } - for(e = child_hash.keys(); e.hasMoreElements();) { - PrefetchPair newpp = (PrefetchPair) e.nextElement(); - tocompare.put(newpp, child_hash.get(newpp)); - } - /* Compare with old Prefetch sets */ - ppSetHasChanged = comparePrefetchSets(currcopy, tocompare); + Enumeration e = null; + Hashtable tocompare = new Hashtable(); + for(e = child_hash.keys(); e.hasMoreElements();) { + PrefetchPair newpp = (PrefetchPair) e.nextElement(); + tocompare.put(newpp, child_hash.get(newpp)); + } - } else { - /* Add the child prefetch set to Curr FlatNode */ - prefetch_hash.put(curr, child_hash); + /* Compare with old Prefetch sets */ + pSetHasChanged = comparePrefetchSets(prefetch_hash.get(curr), tocompare); + if(pSetHasChanged){ + for(int j=0; j child_hash) { + private void processFlatFieldNode(FlatNode curr, Hashtable child_hash) { boolean pSetHasChanged = false; - Hashtable currcopy = (Hashtable) prefetch_hash.get(curr).clone(); + Hashtable currcopy = new Hashtable(); Hashtable tocompare = new Hashtable(); FlatFieldNode currffn = (FlatFieldNode) curr; - Float newprob = new Float((float)1.0); - //1.Get each prefetch pair of the child and match it with the destination temp descriptor of curr FlatFieldNode + /* Do Self analysis of the current node*/ + FieldDescriptor currffn_field = currffn.getField(); + TempDescriptor currffn_src = currffn.getSrc(); + if (currffn_field.getType().isPtr()) { + Boolean b = new Boolean(false); + PrefetchPair pp = new PrefetchPair(currffn_src, (Descriptor) currffn_field, b); + Float prob = new Float((float)1.0); + currcopy.put(pp, prob); + } + + /* Get each prefetch pair of the child and match it with the destination temp descriptor of curr FlatFieldNode */ Enumeration ecld = child_hash.keys(); PrefetchPair currpp = null; PrefetchPair childpp = null; @@ -256,8 +193,7 @@ public class PrefetchAnalysis { childpp = (PrefetchPair) ecld.nextElement(); if (childpp.base == currffn.getDst() && (childpp.getDesc()!= null || childpp.getisTempDesc()!=null)) { if (currffn.getField().getType().isPtr()) { - //pSetHasChanged = true; - //if match exists then create a new Prefetch set with the new prefetch pair in a new hash table + /* Create a new Prefetch set */ ArrayList newdesc = new ArrayList(); ArrayList newbool = new ArrayList(); newdesc.add(currffn.getField()); @@ -266,12 +202,22 @@ public class PrefetchAnalysis { newdesc.addAll(childpp.desc); newbool.addAll(childpp.isTempDesc); PrefetchPair newpp = new PrefetchPair(currffn.getSrc(), newdesc, newbool); + Float newprob = child_hash.get(childpp).floatValue(); tocompare.put(newpp, newprob); child_hash.remove(childpp); + /* Check for independence of prefetch pairs if any in the child prefetch set + * to compute new probability */ + if(child_hash.containsKey(newpp)) { + newprob = (float)(1.0 - ((1.0 - child_hash.get(newpp).floatValue()) * (1.0 - tocompare.get(newpp).floatValue()))); + tocompare.put(newpp, newprob); + child_hash.remove(newpp); + } } } else if(childpp.base == currffn.getDst() && (childpp.getDesc() == null || childpp.getisTempDesc() == null)) { child_hash.remove(childpp); + } else { + continue; } } /* Check if curr prefetch set and the child prefetch set have same prefetch pairs @@ -283,11 +229,8 @@ public class PrefetchAnalysis { for(e = currcopy.keys(); e.hasMoreElements();) { currpp = (PrefetchPair) e.nextElement(); if(currpp.equals(childpp)) { - /* Calculate the new probability */ - Float cprob = child_hash.get(childpp); - Float fprob = currcopy.get(currpp); - // TODO fix this - Float prob = cprob.floatValue() * fprob.floatValue(); + /* Probability of the incoming edge for a FlatFieldNode is always 100% */ + Float prob = currcopy.get(currpp).floatValue(); currcopy.put(currpp, prob); child_hash.remove(childpp); break; @@ -328,12 +271,21 @@ public class PrefetchAnalysis { * It compares the old prefetch set with this new prefetch set and enqueues the parents * of the current node if change occurs and updates the global flatnode hash table * */ - void processFlatElementNode(FlatNode curr, Hashtable child_hash) { + private void processFlatElementNode(FlatNode curr, Hashtable child_hash) { + boolean pSetHasChanged = false; - Hashtable currcopy = (Hashtable) prefetch_hash.get(curr).clone(); + Hashtable currcopy = new Hashtable(); Hashtable tocompare = new Hashtable(); FlatElementNode currfen = (FlatElementNode) curr; - Float newprob = new Float((float)1.0); + + /* Do Self analysis of the current node*/ + TempDescriptor currfen_index = currfen.getIndex(); + TempDescriptor currfen_src = currfen.getSrc(); + if(currfen.getDst().getType().isPtr()) { + PrefetchPair pp = new PrefetchPair(currfen_src, (Descriptor) currfen_index, true); + Float prob = new Float((float)1.0); + currcopy.put(pp, prob); + } /* Get each prefetch pair of the child and match it with the destination temp descriptor of curr FlatFieldNode */ Enumeration ecld = child_hash.keys(); @@ -343,7 +295,7 @@ public class PrefetchAnalysis { childpp = (PrefetchPair) ecld.nextElement(); if (childpp.base == currfen.getDst() && (childpp.getDesc()!= null || childpp.getisTempDesc()!=null)) { if (currfen.getDst().getType().isPtr()) { - //if match exists then create a new Prefetch set with the new prefetch pair in a new hash table + //TODO Modify the Prefetch Pair to insert cases like f=a[i+1] ArrayList newdesc = new ArrayList(); ArrayList newbool = new ArrayList(); newdesc.add(currfen.getIndex()); @@ -352,8 +304,16 @@ public class PrefetchAnalysis { newdesc.addAll(childpp.desc); newbool.addAll(childpp.isTempDesc); PrefetchPair newpp = new PrefetchPair(currfen.getSrc(), newdesc, newbool); + Float newprob = child_hash.get(childpp).floatValue(); tocompare.put(newpp, newprob); child_hash.remove(childpp); + /* Check for independence of prefetch pairs if any in the child prefetch set + * to compute new probability */ + if(child_hash.containsKey(newpp)) { + newprob = (float)(1.0 - ((1.0 - child_hash.get(newpp).floatValue()) * (1.0 - tocompare.get(newpp).floatValue()))); + tocompare.put(newpp, newprob); + child_hash.remove(newpp); + } } } else if(childpp.base == currfen.getDst() && (childpp.getDesc() == null || childpp.getisTempDesc() == null)) { @@ -369,11 +329,8 @@ public class PrefetchAnalysis { for(e = currcopy.keys(); e.hasMoreElements();) { currpp = (PrefetchPair) e.nextElement(); if(currpp.equals(childpp)) { - /* Calculate the new probability */ - Float cprob = child_hash.get(childpp); - Float fprob = currcopy.get(currpp); - // TODO fix this - Float prob = cprob.floatValue() * fprob.floatValue(); + /* Probability of the incoming edge for a FlatElementNode is always 100% */ + Float prob = currcopy.get(currpp).floatValue(); currcopy.put(currpp, prob); child_hash.remove(childpp); break; @@ -409,6 +366,210 @@ public class PrefetchAnalysis { } } + /** This function processes the prefetch set of a FlatSetFieldNode + * It generates a new prefetch set after comparision with its children + * It compares the old prefetch set with this new prefetch set and enqueues the parents + * of the current node if change occurs and then updates the global flatnode hash table + * */ + private void processFlatSetFieldNode(FlatNode curr, Hashtable child_hash) { + boolean pSetHasChanged = false; + Hashtable tocompare = new Hashtable(); + FlatSetFieldNode currfsfn = (FlatSetFieldNode) curr; + PrefetchPair childpp = null; + + /* Get each prefetch pair of the child and match it with the destination temp descriptor of curr FlatFieldNode */ + Enumeration ecld = child_hash.keys(); + while (ecld.hasMoreElements()) { + childpp = (PrefetchPair) ecld.nextElement(); + if (childpp.base == currfsfn.getDst() && (FieldDescriptor)childpp.getDescAt(0)== currfsfn.getField()) { + if(childpp.getDesc()!= null && childpp.getisTempDesc()!=null) { + if(currfsfn.getSrc().getType().isPtr()) { + ArrayList newdesc = new ArrayList(); + ArrayList newbool = new ArrayList(); + newdesc.addAll(1,childpp.desc); + newbool.addAll(1,childpp.isTempDesc); + PrefetchPair newpp = new PrefetchPair(currfsfn.getSrc(), newdesc, newbool); + Float newprob = child_hash.get(childpp).floatValue(); + tocompare.put(newpp, newprob); + child_hash.remove(childpp); + /* Check for independence of prefetch pairs if any in the child prefetch set + * to compute new probability */ + if(child_hash.containsKey(newpp)) { + newprob = (float)(1.0 - ((1.0 - child_hash.get(newpp).floatValue()) * (1.0 - tocompare.get(newpp).floatValue()))); + tocompare.put(newpp, newprob); + child_hash.remove(newpp); + } + } + } + } + } + + /* Merge child prefetch pairs */ + ecld = child_hash.keys(); + while(ecld.hasMoreElements()) { + childpp = (PrefetchPair) ecld.nextElement(); + tocompare.put(childpp, child_hash.get(childpp)); + child_hash.remove(childpp); + } + + /* Compare with the orginal prefetch pairs */ + pSetHasChanged = comparePrefetchSets(prefetch_hash.get(curr), tocompare); + /* Enqueue parent nodes */ + if(pSetHasChanged) { + for(int i=0; i child_hash) { + boolean pSetHasChanged = false; + Hashtable tocompare = new Hashtable(); + PrefetchPair childpp = null; + FlatSetElementNode currfsen = (FlatSetElementNode) curr; + + /* Get each prefetch pair of the child and match it with the destination temp descriptor of curr FlatFieldNode */ + Enumeration ecld = child_hash.keys(); + while (ecld.hasMoreElements()) { + childpp = (PrefetchPair) ecld.nextElement(); + //TODO Add comparision for cases like a[i+1]=f.The following only works for cases like a[i]=f + if ((childpp.base == currfsen.getDst()) && ((TempDescriptor)childpp.getDescAt(0)== currfsen.getIndex())) { + if(childpp.getDesc()!= null && childpp.getisTempDesc()!=null) { + if(currfsen.getSrc().getType().isPtr()) { + ArrayList newdesc = new ArrayList(); + ArrayList newbool = new ArrayList(); + newdesc.addAll(1,childpp.desc); + newbool.addAll(1,childpp.isTempDesc); + PrefetchPair newpp = new PrefetchPair(currfsen.getSrc(), newdesc, newbool); + Float newprob = child_hash.get(childpp).floatValue(); + tocompare.put(newpp, newprob); + child_hash.remove(childpp); + /* Check for independence of prefetch pairs if any in the child prefetch set + * to compute new probability */ + if(child_hash.containsKey(newpp)) { + newprob = (float)(1.0 - ((1.0 - child_hash.get(newpp).floatValue()) * (1.0 - tocompare.get(newpp).floatValue()))); + tocompare.put(newpp, newprob); + child_hash.remove(newpp); + } + } + } + } + } + + /* Merge child prefetch pairs */ + ecld = child_hash.keys(); + while(ecld.hasMoreElements()) { + childpp = (PrefetchPair) ecld.nextElement(); + tocompare.put(childpp, child_hash.get(childpp)); + child_hash.remove(childpp); + } + + /* Compare with the orginal prefetch pairs */ + pSetHasChanged = comparePrefetchSets(prefetch_hash.get(curr), tocompare); + /* Enqueue parent nodes */ + if(pSetHasChanged) { + for(int i=0; i child_hash) { + boolean pSetHasChanged = false; + int index; + Hashtable tocompare = new Hashtable(); + FlatOpNode currfopn = (FlatOpNode) curr; + Enumeration ecld = null; + PrefetchPair childpp = null; + + /* Check the Operation type of flatOpNode */ + if(currfopn.getOp().getOp()== Operation.ASSIGN) { + ecld = child_hash.keys(); + while (ecld.hasMoreElements()) { + childpp = (PrefetchPair) ecld.nextElement(); + ArrayList copychildpp = (ArrayList) childpp.desc.clone(); + ArrayList copybool = (ArrayList) childpp.isTempDesc.clone(); + /* Base of child prefetch pair same as destination of the current FlatOpNode */ + if(childpp.base == currfopn.getDest()) { + ArrayList newdesc = new ArrayList(); + ArrayList newbool = new ArrayList(); + newdesc.addAll(childpp.desc); + newbool.addAll(childpp.isTempDesc); + PrefetchPair newpp = new PrefetchPair(currfopn.getLeft(), newdesc, newbool); + Float newprob = child_hash.get(childpp).floatValue(); + tocompare.put(newpp, newprob); + child_hash.remove(childpp); + /* Check for independence of prefetch pairs if any in the child prefetch set + * to compute new probability */ + if(child_hash.containsKey(newpp)) { + newprob = (float)(1.0 - ((1.0 - child_hash.get(newpp).floatValue()) * (1.0 - tocompare.get(newpp).floatValue()))); + tocompare.put(newpp, newprob); + child_hash.remove(newpp); + } + /* Any member of the desc of child prefetch pair is same as destination of the current FlatOpNode */ + } else if(copychildpp.contains(currfopn.getDest())) { + index = copychildpp.indexOf((TempDescriptor)currfopn.getDest()); + copychildpp.set(index, currfopn.getLeft()); + /* Check if TempDescriptor */ + if(copybool.get(index).booleanValue() == false){ + copybool.set(index, true); + } + ArrayList newdesc = new ArrayList(); + ArrayList newbool = new ArrayList(); + newdesc.addAll(copychildpp); + newbool.addAll(copybool); + PrefetchPair newpp = new PrefetchPair(childpp.base, newdesc, newbool); + Float newprob = child_hash.get(childpp).floatValue(); + tocompare.put(newpp, newprob); + child_hash.remove(childpp); + /* Check for independence of prefetch pairs if any in the child prefetch set + * to compute new probability */ + if(child_hash.containsKey(newpp)) { + newprob = (float)(1.0 - ((1.0 - child_hash.get(newpp).floatValue()) * (1.0 - tocompare.get(newpp).floatValue()))); + tocompare.put(newpp, newprob); + child_hash.remove(newpp); + } + + }else { + continue; + } + } + } else if(currfopn.getRight()!=null) { + //FIXME + } else { + //FIXME + } + + /* Merge child prefetch pairs */ + ecld = child_hash.keys(); + while(ecld.hasMoreElements()) { + childpp = (PrefetchPair) ecld.nextElement(); + tocompare.put(childpp, child_hash.get(childpp)); + child_hash.remove(childpp); + } + + /* Compare with the orginal prefetch pairs */ + pSetHasChanged = comparePrefetchSets(prefetch_hash.get(curr), tocompare); + /* Enqueue parent nodes */ + if(pSetHasChanged) { + for(int i=0; i desc; - ArrayList isTempDesc; + ArrayList isTempDesc; //Keeps track if the desc is a FieldDescriptor or TempDescriptor. Has same size() as desc + public PrefetchPair() { } @@ -68,15 +69,12 @@ public class PrefetchPair { public int hashCode() { int hashcode = base.toString().hashCode(); - //int hashcode = base.hashCode(); if(desc != null) { - // if(getDesc() != null) { ListIterator li = desc.listIterator(); while(li.hasNext()) { hashcode = hashcode ^ li.next().toString().hashCode(); } } - //System.out.println("DEBUG -> hashcode for: " + base.toString() + " " + hashcode); return hashcode; } @@ -103,7 +101,6 @@ public class PrefetchPair { if(o instanceof PrefetchPair) { PrefetchPair pp = (PrefetchPair) o; if(base != pp.base) { - //System.out.println("PP: returning false for:" + base.toString() + " " + pp.base.toString()); return false; } if (desc == null && pp.desc == null) {