bug fixes to handle propagation for FlatOpNode method for simple cases
authoradash <adash>
Wed, 31 Oct 2007 21:19:24 +0000 (21:19 +0000)
committeradash <adash>
Wed, 31 Oct 2007 21:19:24 +0000 (21:19 +0000)
bug fixes for null exception for prefetch hashtable
remove unnecessary print statements

Robust/src/Analysis/Prefetch/PrefetchAnalysis.java
Robust/src/Analysis/Prefetch/PrefetchPair.java

index c171eb1ade406019e3f8ccf52edc497f3081d8d2..ef36272f6fea7f3fe4eca2cddfb4ece38c7cd756 100644 (file)
@@ -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<PrefetchPair, Float> nodehash = new Hashtable<PrefetchPair, Float>();
+           /* 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<PrefetchPair, Float> nodehash = new Hashtable<PrefetchPair, Float>();
-           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<PrefetchPair, Float> child_hash = new Hashtable<PrefetchPair, Float>();
            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<PrefetchPair, Float> currcopy = (Hashtable<PrefetchPair,Float>)prefetch_hash.get(curr).clone();
-                                           Hashtable<PrefetchPair, Float> tocompare = new Hashtable<PrefetchPair, Float>();
-                                           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<PrefetchPair, Float> tocompare = new Hashtable<PrefetchPair, Float>();
+                                   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<curr.numPrev(); j++) {
+                                                   tovisit.add(curr.getPrev(j));
+                                           }
+                                           /* Overwrite the new prefetch set to the global hash table */
+                                           prefetch_hash.put(curr,tocompare); 
                                    }
                                    break;
                    }
            } 
-           return ppSetHasChanged;
+           return pSetHasChanged;
     }
     
     /**This function compares all the prefetch pairs in a Prefetch set hashtable and
@@ -209,6 +136,7 @@ public class PrefetchAnalysis {
            boolean hasChanged = false;
            PrefetchPair oldpp = null;
            PrefetchPair newpp = null;
+
            if(oldPrefetchSet.size() != newPrefetchSet.size()) {
                    return true;
            } else {
@@ -241,14 +169,23 @@ public class PrefetchAnalysis {
      * If old prefetch set is not same as new prefetch set then enqueue the parents 
      * of the current FlatFieldNode
      * */
-    void processFlatFieldNode(FlatNode curr, Hashtable<PrefetchPair, Float> child_hash) {
+    private void processFlatFieldNode(FlatNode curr, Hashtable<PrefetchPair, Float> child_hash) {
            boolean pSetHasChanged = false;
-           Hashtable<PrefetchPair, Float> currcopy = (Hashtable<PrefetchPair,Float>) prefetch_hash.get(curr).clone();
+           Hashtable<PrefetchPair, Float> currcopy = new Hashtable<PrefetchPair, Float>();
            Hashtable<PrefetchPair, Float> tocompare = new Hashtable<PrefetchPair, Float>();
            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<Descriptor> newdesc = new ArrayList<Descriptor>();
                                    ArrayList<Boolean> newbool = new ArrayList<Boolean>();
                                    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<PrefetchPair, Float> child_hash) {
+    private void processFlatElementNode(FlatNode curr, Hashtable<PrefetchPair, Float> child_hash) {
+           
            boolean pSetHasChanged = false;
-           Hashtable<PrefetchPair, Float> currcopy = (Hashtable<PrefetchPair,Float>) prefetch_hash.get(curr).clone();
+           Hashtable<PrefetchPair, Float> currcopy = new Hashtable<PrefetchPair, Float>();
            Hashtable<PrefetchPair, Float> tocompare = new Hashtable<PrefetchPair, Float>();
            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<Descriptor> newdesc = new ArrayList<Descriptor>();
                                    ArrayList<Boolean> newbool = new ArrayList<Boolean>();
                                    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<PrefetchPair, Float> child_hash) {
+           boolean pSetHasChanged = false;
+           Hashtable<PrefetchPair, Float> tocompare = new Hashtable<PrefetchPair, Float>();
+           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<Descriptor> newdesc = new ArrayList<Descriptor>();
+                                           ArrayList<Boolean> newbool = new ArrayList<Boolean>();
+                                           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<curr.numPrev(); i++) {
+                           tovisit.add(curr.getPrev(i));
+                   }
+                   /* Overwrite the new prefetch set to the global hash table */
+                   prefetch_hash.put(curr,tocompare); 
+           } 
+    }
+
+    /** This function processes the prefetch set of a FlatSeElementNode
+     * 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 processFlatSetElementNode(FlatNode curr, Hashtable<PrefetchPair, Float> child_hash) {
+           boolean pSetHasChanged = false;
+           Hashtable<PrefetchPair, Float> tocompare = new Hashtable<PrefetchPair, Float>();
+           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<Descriptor> newdesc = new ArrayList<Descriptor>();
+                                           ArrayList<Boolean> newbool = new ArrayList<Boolean>();
+                                           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<curr.numPrev(); i++) {
+                           tovisit.add(curr.getPrev(i));
+                   }
+                   /* Overwrite the new prefetch set to the global hash table */
+                   prefetch_hash.put(curr,tocompare); 
+           } 
+    }
+    /** This function applies rules and does analysis for a FlatOpNode 
+     *  And updates the global prefetch hashtable
+     * */
+    private void processFlatOpNode(FlatNode curr, Hashtable<PrefetchPair, Float> child_hash) {
+           boolean pSetHasChanged = false;
+           int index;
+           Hashtable<PrefetchPair, Float> tocompare = new Hashtable<PrefetchPair, Float>();
+           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<Descriptor> copychildpp = (ArrayList<Descriptor>) childpp.desc.clone();
+                           ArrayList<Boolean> copybool = (ArrayList<Boolean>) childpp.isTempDesc.clone();
+                           /* Base of child prefetch pair same as destination of the current FlatOpNode */
+                           if(childpp.base == currfopn.getDest()) {
+                                   ArrayList<Descriptor> newdesc = new ArrayList<Descriptor>();
+                                   ArrayList<Boolean> newbool = new ArrayList<Boolean>();
+                                   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<Descriptor> newdesc = new ArrayList<Descriptor>();
+                                   ArrayList<Boolean> newbool = new ArrayList<Boolean>();
+                                   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<curr.numPrev(); i++) {
+                           tovisit.add(curr.getPrev(i));
+                   }
+                   /* Overwrite the new prefetch set to the global hash table */
+                   prefetch_hash.put(curr,tocompare); 
+           } 
+    }
 
     /** This function prints the Prefetch pairs of a given flatnode */
     void printPrefetchPairs(FlatNode fn) {
@@ -420,6 +581,8 @@ public class PrefetchAnalysis {
                            System.out.print(pp.toString() + ", ");
                    }
                    System.out.println(")");
+           } else {
+                   System.out.println("Flatnode is currently not present in the global hash: Prefetch Set is Empty");
            }
     }
 
index a56fd973c5ce72e4d091cbdde43fc134fa860209..ee4c8c91282f99426173b1a1f7456750f113c2f3 100644 (file)
@@ -6,7 +6,8 @@ import IR.*;
 public class PrefetchPair {
        TempDescriptor base;
        ArrayList<Descriptor> desc;
-       ArrayList<Boolean> isTempDesc;
+       ArrayList<Boolean> 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) {