Added some intial code for Building flatcode for prefetch node
authoradash <adash>
Fri, 30 Nov 2007 22:09:08 +0000 (22:09 +0000)
committeradash <adash>
Fri, 30 Nov 2007 22:09:08 +0000 (22:09 +0000)
Modified prefetch analyisis to take care of FlatCastNode and FlatTagDeclaration

Robust/src/Analysis/Prefetch/PrefetchAnalysis.java
Robust/src/IR/Flat/BuildCode.java
Robust/src/IR/Flat/FlatPrefetchNode.java
Robust/src/Runtime/DSTM/interface/trans.c

index b566bbc263a92b373e0dd4f82d6a6a81663fa59b..c62040a468cfd4e0df9fec9c53e9e5f1cba07380 100644 (file)
@@ -114,7 +114,6 @@ public class PrefetchAnalysis {
                        doInsPrefetchAnalysis(fm);
                        if(newprefetchset.size() > 0) {
                                addFlatPrefetchNode(newprefetchset);
-                               printMethod(fm);
                        }
                }
        }
@@ -195,7 +194,7 @@ public class PrefetchAnalysis {
                                }
                                break;
                        case FKind.FlatOpNode:
-                               processFlatOpNode(curr, child_prefetch_set_copy,parentpmap);
+                               processFlatOpNode(curr, child_prefetch_set_copy, parentpmap);
                                break;
                        case FKind.FlatLiteralNode:
                                processFlatLiteralNode(curr, child_prefetch_set_copy, parentpmap);
@@ -213,7 +212,7 @@ public class PrefetchAnalysis {
                                processDefaultCase(curr,child_prefetch_set_copy, parentpmap);
                                break;
                        case FKind.FlatCastNode:
-                               processDefaultCase(curr,child_prefetch_set_copy, parentpmap);
+                               processFlatCastNode(curr, child_prefetch_set_copy, parentpmap);
                                break;
                        case FKind.FlatFlagActionNode:
                                processDefaultCase(curr,child_prefetch_set_copy, parentpmap);
@@ -225,7 +224,7 @@ public class PrefetchAnalysis {
                                processDefaultCase(curr,child_prefetch_set_copy, parentpmap);
                                break;
                        case FKind.FlatTagDeclaration:
-                               processDefaultCase(curr,child_prefetch_set_copy, parentpmap);
+                               processFlatTagDeclaration(curr, child_prefetch_set_copy, parentpmap);
                                break;
                        default:
                                System.out.println("NO SUCH FLATNODE");
@@ -1104,6 +1103,94 @@ public class PrefetchAnalysis {
                } 
        }
 
+       /** This functions processes for FlatCastNode
+        * for e.g x = (cast type) y followed by childnode with prefetch set x.f
+        * then drop the prefetches beyond this FlatCastNode */
+       private void processFlatCastNode(FlatNode curr, Hashtable<PrefetchPair, Float>child_prefetch_set_copy, 
+                       Hashtable<FlatNode, PairMap> parentpmap) {
+               boolean pSetHasChanged = false;
+               Hashtable<PrefetchPair, Float> tocompare = new Hashtable<PrefetchPair, Float>();
+               FlatCastNode currfcn = (FlatCastNode) curr;
+               Float newprob = new Float((float)0.0);
+               PairMap pm = new PairMap();
+               PrefetchPair childpp = null;
+               Enumeration ecld = null;
+
+               ecld = child_prefetch_set_copy.keys();
+               while (ecld.hasMoreElements()) {
+                       childpp = (PrefetchPair) ecld.nextElement();
+                       if(childpp.base == currfcn.getDst()){
+                               child_prefetch_set_copy.remove(childpp);
+                       } else {
+                               tocompare.put(childpp, child_prefetch_set_copy.get(childpp));
+                               pm.addPair(childpp, childpp);
+                               child_prefetch_set_copy.remove(childpp);
+                       }
+               }
+
+               /* Create prefetch mappings for child nodes */
+               if(!pm.isEmpty()) {
+                       parentpmap.put(curr, pm);
+               }
+               pmap_hash.put(curr.getNext(0), parentpmap);
+
+               /* Compare with the old prefetch set */
+               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 functions processes for FlatTagDeclaration
+        * for e.g x = (cast type) y followed by childnode with prefetch set x.f
+        * then drop the prefetches beyond this FlatTagDeclaration */
+       private void processFlatTagDeclaration(FlatNode curr, Hashtable<PrefetchPair, Float>child_prefetch_set_copy, 
+                       Hashtable<FlatNode, PairMap> parentpmap) {
+               boolean pSetHasChanged = false;
+               Hashtable<PrefetchPair, Float> tocompare = new Hashtable<PrefetchPair, Float>();
+               FlatTagDeclaration currftd = (FlatTagDeclaration) curr;
+               Float newprob = new Float((float)0.0);
+               PairMap pm = new PairMap();
+               PrefetchPair childpp = null;
+               Enumeration ecld = null;
+
+               ecld = child_prefetch_set_copy.keys();
+               while (ecld.hasMoreElements()) {
+                       childpp = (PrefetchPair) ecld.nextElement();
+                       if(childpp.base == currftd.getDst()){
+                               child_prefetch_set_copy.remove(childpp);
+                       } else {
+                               tocompare.put(childpp, child_prefetch_set_copy.get(childpp));
+                               pm.addPair(childpp, childpp);
+                               child_prefetch_set_copy.remove(childpp);
+                       }
+               }
+
+               /* Create prefetch mappings for child nodes */
+               if(!pm.isEmpty()) {
+                       parentpmap.put(curr, pm);
+               }
+               pmap_hash.put(curr.getNext(0), parentpmap);
+
+               /* Compare with the old prefetch set */
+               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 */
        private void printPrefetchPairs(FlatNode fn) {
                if(prefetch_hash.containsKey(fn)) {
@@ -1216,7 +1303,7 @@ public class PrefetchAnalysis {
                                                        FlatNode parentnode = (FlatNode) e.nextElement();
                                                        PairMap pm = (PairMap) ppairmaphash.get(parentnode);
                                                        if(pset1_hash.containsKey(parentnode)) {
-                                                               Set pset = pset1_hash.get(parentnode);
+                                                               HashSet pset = pset1_hash.get(parentnode);
                                                                if(!pset.isEmpty()) {
                                                                        if(ppairIsPresent = (pset.contains((PrefetchPair) pm.getPair(pp)))) {
                                                                                mapIsPresent = ppairIsPresent && mapIsPresent;
@@ -1272,20 +1359,28 @@ public class PrefetchAnalysis {
                                }
                        }
                        pset1_hash.put(fn, pset1);
-               }
 
-               /* To insert prefetch apply rule */
-               HashSet s = null;
-               if(!newpset.isEmpty() && !pset2.isEmpty()) {
-                       for(Iterator it = newpset.iterator(); it.hasNext();) {
-                               PrefetchPair pp = (PrefetchPair) it.next();
-                               if(!pset2.contains(pp)) {
-                                       s.add(pp);
+                       /* To insert prefetch apply rule */
+                       HashSet<PrefetchPair> s = new HashSet<PrefetchPair>();
+                       //if(!newpset.isEmpty() && !pset2.isEmpty()) {
+                       if(!newpset.isEmpty()) {
+                               if(!pset2.isEmpty()) {
+                                       for(Iterator it = newpset.iterator(); it.hasNext();) {
+                                               PrefetchPair pp = (PrefetchPair) it.next();
+                                               if(!pset2.contains(pp)) {
+                                                       s.add(pp);
+                                               }
+                                       }
+                               } else {
+                                       for(Iterator it = newpset.iterator(); it.hasNext();) {
+                                               PrefetchPair pp = (PrefetchPair) it.next();
+                                               s.add(pp);
+                                       }
                                }
                        }
-               }
-               if(s != null) {
-                       newprefetchset.put(fn, s); 
+                       if(s.size() > 0) {
+                               newprefetchset.put(fn, s); 
+                       }
                }
        }
 
@@ -1301,11 +1396,11 @@ public class PrefetchAnalysis {
                        for(i = 0; i< newprefetchset.get(fn).size(); i++) {
                                fpn.insAllpp((HashSet)newprefetchset.get(fn));
                        }
+                       //System.out.println("The HashSet of prefetch pairs are "+ fpn.getPrefetchPairs());
                        if(fn.kind() == FKind.FlatMethod) {
                                FlatNode nn = fn.getNext(0);
                                fn.setNext(0, fpn);
                                fpn.addNext(nn);
-
                        } else {
                                while(fn.numPrev() > 0) {
                                        FlatNode nn = fn.getPrev(0);
index 7174ba9139d61a2ec42670fefd80c80ee576dd98..11b93c840d9c889e9ced8429144005a588f73af0 100644 (file)
@@ -15,6 +15,7 @@ import Analysis.TaskStateAnalysis.SafetyAnalysis;
 import Analysis.TaskStateAnalysis.TaskIndex;
 import Analysis.Locality.LocalityAnalysis;
 import Analysis.Locality.LocalityBinding;
+import Analysis.Prefetch.*;
 
 public class BuildCode {
     State state;
@@ -324,12 +325,12 @@ public class BuildCode {
        /* Generate code for methods */
        if (state.DSM) {
            for(Iterator<LocalityBinding> lbit=locality.getLocalityBindings().iterator();lbit.hasNext();) {
-               LocalityBinding lb=lbit.next();
-               MethodDescriptor md=lb.getMethod();
-               FlatMethod fm=state.getMethodFlat(md);
-               if (!md.getModifiers().isNative()) {
-                   generateFlatMethod(fm, lb, outmethod);
-               }
+               LocalityBinding lb=lbit.next();
+                MethodDescriptor md=lb.getMethod();
+               FlatMethod fm=state.getMethodFlat(md);
+               if (!md.getModifiers().isNative()) {
+                       generateFlatMethod(fm, lb, outmethod);
+               }
            }
        } else {
            Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
@@ -1412,11 +1413,47 @@ public class BuildCode {
        case FKind.FlatFlagActionNode:
            generateFlatFlagActionNode(fm, lb, (FlatFlagActionNode) fn, output);
            return;
+       case FKind.FlatPrefetchNode:
+           generateFlatPrefetchNode(fm,lb, (FlatPrefetchNode) fn, output);
+           return;
        }
        throw new Error();
-
     }
-    
+    public void generateFlatPrefetchNode(FlatMethod fm, LocalityBinding lb, FlatPrefetchNode fpn, PrintWriter output) {
+       System.out.println("Inside generateFlatPrefetchNode()");
+       if (state.PREFETCH) {
+           System.out.println("The Prefetch pairs to be fetched are "+ fpn.hspp);
+           Iterator it = fpn.hspp.iterator();
+           for(;it.hasNext();) {
+                PrefetchPair pp = (PrefetchPair) it.next();
+                //TODO handle arrays in prefetch tuples, currently only handle fields
+                Integer statusbase = locality.getNodePreTempInfo(lb,fpn).get(pp.base);
+                System.out.println("DEBUG-> generateFlatPrefetchNode()" + statusbase);
+                if(statusbase == LocalityAnalysis.GLOBAL) {
+                    // Generate oid for base
+                } else {
+                    for(int i = 0; i<pp.desc.size(); i++) {
+                       Object o = pp.desc.get(i);
+                       if(!(o instanceof IndexDescriptor)) {
+                               FieldDescriptor fd = (FieldDescriptor) o;
+                               Integer statusfd = locality.getNodePreTempInfo(lb,fpn).get(fd);
+                               System.out.println("DEBUG-> generateFlatPrefetchNode() fd" + statusfd);
+                               //find out the locality of the fieldDescriptor
+                               if(statusfd == LocalityAnalysis.GLOBAL) {
+                                       //generate oid for it
+                               }
+                       }
+                    }
+                }
+             }
+             //Each temp descriptor can be an oid
+            //Find locality of each prefetch tuple in the FLatPrefetchNode
+            //Separate them as Local or Global
+            //generate oids and offset value for prefetch tuple
+       }
+    }   
+
     public void generateFlatGlobalConvNode(FlatMethod fm, LocalityBinding lb, FlatGlobalConvNode fgcn, PrintWriter output) {
        if (lb!=fgcn.getLocality())
            return;
@@ -1700,6 +1737,7 @@ public class BuildCode {
            output.println(generateTemp(fm, ffn.getDst(),lb)+"="+ generateTemp(fm,ffn.getSrc(),lb)+"->"+ ffn.getField().getSafeSymbol()+";");
     }
 
+
     private void generateFlatSetFieldNode(FlatMethod fm, LocalityBinding lb, FlatSetFieldNode fsfn, PrintWriter output) {
        if (fsfn.getField().getSymbol().equals("length")&&fsfn.getDst().getType().isArray())
            throw new Error("Can't set array length");
index 7a8914c058849401184b47bf93c05330ee15d85e..81a20d1d3fa5c0970ed2c09b8d9353bfde953299 100644 (file)
@@ -3,10 +3,10 @@ import Analysis.Prefetch.*;
 import java.util.*;
 
 public class FlatPrefetchNode extends FlatNode {
-       HashSet<PrefetchPair> pp;
+       HashSet<PrefetchPair> hspp;
 
        public FlatPrefetchNode() {
-               pp = new HashSet<PrefetchPair>();
+               hspp = new HashSet<PrefetchPair>();
        }
 
        public String toString() {
@@ -18,14 +18,14 @@ public class FlatPrefetchNode extends FlatNode {
        }
 
        public void insPrefetchPair(PrefetchPair pp) {
-               this.pp.add(pp);
+               hspp.add(pp);
        }
 
        public void insAllpp(HashSet<PrefetchPair> hspp) {
-               this.pp.addAll(hspp);
+               this.hspp.addAll(hspp);
        }
 
        public HashSet<PrefetchPair> getPrefetchPairs() {
-               return this.pp;
+               return hspp;
        }
 }
index e76fc95c74694ff09550a781035e3dc1f60e8f5c..d702c66bc346bd217469d829189dbdd7714f38b5 100644 (file)
@@ -47,6 +47,7 @@ unsigned int oidMin;
 unsigned int oidMax;
 
 void printhex(unsigned char *, int);
+plistnode_t *createPiles(transrecord_t *);
 
 void printhex(unsigned char *ptr, int numBytes)
 {
@@ -62,7 +63,6 @@ void printhex(unsigned char *ptr, int numBytes)
        return;
 }
 
-plistnode_t *createPiles(transrecord_t *);
 inline int arrayLength(int *array) {
        int i;
        for(i=0 ;array[i] != -1; i++)
@@ -132,6 +132,30 @@ int dstmStartup(const char * option) {
 
 }
 
+//TODO Use this later
+void *pCacheAlloc(objstr_t *store, unsigned int size) {
+       void *tmp;
+       objstr_t *ptr;
+       ptr = store;
+       int success = 0;
+
+       while(ptr->next != NULL) {
+               /* check if store is empty */
+               if(((unsigned int)ptr->top - (unsigned int)ptr - sizeof(objstr_t) + size) <= ptr->size) {
+                       tmp = ptr->top;
+                       ptr->top += size;
+                       success = 1;
+                       return tmp;
+               } else {
+                       ptr = ptr-> next;
+               }
+       }
+
+       if(success == 0) {
+               printf("DEBUG-> Unable to insert object in Prefetch cache\n");
+               return NULL;
+       }
+}
 
 /* This function initiates the prefetch thread
  * A queue is shared between the main thread of execution
@@ -143,6 +167,8 @@ void transInit() {
        int retval;
        //Create and initialize prefetch cache structure
        prefetchcache = objstrCreate(PREFETCH_CACHE_SIZE);
+       //prefetchcache->next = objstrCreate(PREFETCH_CACHE_SIZE);
+       //prefetchcache->next->next = objstrCreate(PREFETCH_CACHE_SIZE);
 
        /* Initialize attributes for mutex */
        pthread_mutexattr_init(&prefetchcache_mutex_attr);