changes.
authoryeom <yeom>
Thu, 7 Jan 2010 04:19:08 +0000 (04:19 +0000)
committeryeom <yeom>
Thu, 7 Jan 2010 04:19:08 +0000 (04:19 +0000)
Robust/src/Analysis/MLP/ConflictGraph.java
Robust/src/Analysis/MLP/MLPAnalysis.java
Robust/src/IR/Flat/BuildCode.java
Robust/src/Runtime/mlp_runtime.c
Robust/src/Runtime/mlp_runtime.h

index 53933c870c45446c1f0d83752d5d3ce3d0c2b81b..508dbfe4fe9db0850dff11170b8e06f0037b82c8 100644 (file)
@@ -2,6 +2,7 @@ package Analysis.MLP;
 
 import java.io.BufferedWriter;
 import java.io.FileWriter;
+import java.util.Collection;
 import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Iterator;
@@ -93,6 +94,7 @@ public class ConflictGraph {
                                        }
                                }                                                               
                        }               
+                       
                }
 
                if (readEffectsSet != null) {
@@ -479,6 +481,108 @@ public class ConflictGraph {
 
                return resultSet;
        }
+       
+       public Set<Integer> getConnectedConflictNodeSet(ParentChildConflictsMap conflictsMap){
+               
+               HashSet<Integer> nodeIDSet = new HashSet<Integer>();
+               
+               Set<Entry<String, ConflictNode>> s = id2cn.entrySet();
+               Iterator<Entry<String, ConflictNode>> i = s.iterator();
+               
+               Collection<StallSite> stallSites=conflictsMap.getStallMap().values();
+               for (Iterator iterator = stallSites.iterator(); iterator.hasNext();) {
+                       StallSite stallSite = (StallSite) iterator.next();
+                       while (i.hasNext()) {
+                               Entry<String, ConflictNode> entry = i.next();
+                               ConflictNode node = entry.getValue();
+
+                               if (node instanceof StallSiteNode) {
+                                       StallSiteNode stallSiteNode = (StallSiteNode) node;
+                                       if (stallSiteNode.getStallSite() == stallSite) {
+                                               HashSet<ConflictEdge> edgeSet = stallSiteNode.getEdgeSet();
+                                               for (Iterator iter2 = edgeSet.iterator(); iter2.hasNext();) {
+                                                       ConflictEdge conflictEdge = (ConflictEdge) iter2.next();
+                                                       nodeIDSet.addAll(getConnectedConflictNode(conflictEdge));
+                                               }
+                                       }
+                               }
+                       }
+               }
+               
+               return nodeIDSet;
+               
+       }
+       
+       private Set<Integer> getConnectedConflictNode(ConflictEdge conflictEdge){
+               
+               HashSet<Integer> nodeIDSet = new HashSet<Integer>();
+               
+               if(conflictEdge.getVertexU() instanceof LiveInNode){
+                       LiveInNode lin=(LiveInNode)conflictEdge.getVertexU();
+                       nodeIDSet.add(new Integer(lin.getSESEIdentifier()));
+               }
+               if(conflictEdge.getVertexV() instanceof LiveInNode){
+                       LiveInNode lin=(LiveInNode)conflictEdge.getVertexV();
+                       nodeIDSet.add(new Integer(lin.getSESEIdentifier()));
+               }
+               
+               return nodeIDSet;
+       }
+       
+       private Set<Integer> getConnectedConflictNode(ConflictEdge conflictEdge, int seseID){
+               
+               HashSet<Integer> nodeIDSet = new HashSet<Integer>();
+               
+               if(conflictEdge.getVertexU() instanceof LiveInNode){
+                       LiveInNode lin=(LiveInNode)conflictEdge.getVertexU();
+                       if(lin.getSESEIdentifier()!=seseID){
+                               nodeIDSet.add(new Integer(lin.getSESEIdentifier()));
+                       }                                                       
+               }else{
+                       // it is stall site
+                       nodeIDSet.add(new Integer(-1));
+               }       
+               if(conflictEdge.getVertexV() instanceof LiveInNode){
+                       LiveInNode lin=(LiveInNode)conflictEdge.getVertexV();
+                       if(lin.getSESEIdentifier()!=seseID){
+                               nodeIDSet.add(new Integer(lin.getSESEIdentifier()));
+                       }                                                       
+               }else{
+                       // it is stall site
+                       nodeIDSet.add(new Integer(-1));
+               }       
+               
+               return nodeIDSet;
+       }
+       
+       public Set<Integer> getConnectedConflictNodeSet(int seseID){
+               
+               HashSet<Integer> nodeIDSet = new HashSet<Integer>();
+               
+               Set<Entry<String, ConflictNode>> s = id2cn.entrySet();
+               Iterator<Entry<String, ConflictNode>> i = s.iterator();
+               
+               while (i.hasNext()) {
+                       Entry<String, ConflictNode> entry = i.next();
+                       ConflictNode node = entry.getValue();
+
+                       if (node instanceof LiveInNode) {
+                               LiveInNode liveInNode = (LiveInNode) node;
+                               if (liveInNode.getSESEIdentifier() == seseID) {
+                                       HashSet<ConflictEdge> edgeSet = liveInNode.getEdgeSet();
+                                       for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) {
+                                               ConflictEdge conflictEdge = (ConflictEdge) iterator.next();
+                                               //
+                                               nodeIDSet.addAll(getConnectedConflictNode(conflictEdge,seseID));
+                                               //
+                                       }
+                               }
+                       }
+               }
+               
+               return nodeIDSet;
+               
+       }
 
        public Set<Long> getAllocationSiteIDSetBySESEID(int seseID) {
 
@@ -497,6 +601,9 @@ public class ConflictGraph {
                                        HashSet<ConflictEdge> edgeSet = liveInNode.getEdgeSet();
                                        for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) {
                                                ConflictEdge conflictEdge = (ConflictEdge) iterator.next();
+                                               //
+                                               getConnectedConflictNode(conflictEdge,seseID);
+                                               //
                                                if (conflictEdge.getType() == ConflictEdge.COARSE_GRAIN_EDGE) {
                                                        allocSiteIDSet.addAll(getHRNIdentifierSet(conflictEdge.getVertexU()));
                                                        allocSiteIDSet.addAll(getHRNIdentifierSet(conflictEdge.getVertexV()));
index 53cc78fbef8f5287a7b555c6568d3028757f067d..76f0069b1962e1c8423c7513eec10528b3771a0c 100644 (file)
@@ -3431,4 +3431,8 @@ public class MLPAnalysis {
          return conflictsResults;
   }
   
+  public Hashtable<FlatNode, SESESummary> getSeseSummaryMap(){
+         return seseSummaryMap;
+  }
+  
 }
index aa242605bb0bf1afe66b90d8a31162a22cf658d7..8c94b32a15c02c839ebcd0378f796ae0fbd44287 100644 (file)
@@ -2701,20 +2701,47 @@ public class BuildCode {
          TempDescriptor dynVar = dynItr.next();
          output.println("   "+dynVar+"_srcSESE = NULL;");
        }
-      }     
-      
-      // eom
-      // handling stall site
-      ParentChildConflictsMap conflictsMap=mlpa.getConflictsResults().get(fn);
-               if (conflictsMap != null) {
        
+        // eom
+    // handling stall site
+    
+    ParentChildConflictsMap conflictsMap=mlpa.getConflictsResults().get(fn);
+    
+               if (conflictsMap != null) {
+
                        Set<Long> allocSet = conflictsMap
                                        .getAllocationSiteIDSetofStallSite();
        
                        if (allocSet.size() > 0) {
+                               
+                               FlatNode enclosingFlatNode=null;
+                               if( currentSESE.getIsCallerSESEplaceholder() && currentSESE.getParent()==null){
+                                       enclosingFlatNode=currentSESE.getfmEnclosing();
+                               }else{
+                                       enclosingFlatNode=currentSESE;
+                               }
+                               
+                               ConflictGraph graph=mlpa.getConflictGraphResults().get(enclosingFlatNode);
+                               Set<Integer> connectedSet=graph.getConnectedConflictNodeSet(conflictsMap);
+                               
                                output.println("   /*  stall on parent's stall sites */");
                                output.println("  {");
                                output.println("     pthread_mutex_lock( &(seseCaller->lock) );");
+                           //
+                               output.println("     ConflictNode* node;");
+                               for (Iterator iterator = connectedSet.iterator(); iterator
+                                               .hasNext();) {
+                                       Integer integer = (Integer) iterator.next();
+                                       //output.print(" "+integer);
+                                       if(integer.intValue()<0){
+                                               output.println("     node=mlpCreateConflictNode(seseCaller->classID);");
+                                       }else{
+                                               output.println("     node=mlpCreateConflictNode( "+integer+" );");
+                                       }
+                                       output.println("     addNewConflictNode(node, seseCaller->connectedList);");
+                               }
+                               //
+                               
                                output.println("     psem_init( &(seseCaller->memoryStallSiteSem) );");
                                output.println("     int qIdx;");
                                output.println("     int takeCount=0;");
@@ -2735,6 +2762,7 @@ public class BuildCode {
                                output.println("  }");
                        }
                }
+      }     
     }
 
     switch(fn.kind()) {
@@ -3296,6 +3324,9 @@ public class BuildCode {
     output.println("     psem_init( &(seseToIssue->common.stallSem) );");
 
     output.println("     seseToIssue->common.forwardList = createQueue();");
+    //eom
+    output.println("     seseToIssue->common.connectedList = createQueue();");
+    //
     output.println("     seseToIssue->common.unresolvedDependencies = 0;");
     output.println("     pthread_cond_init( &(seseToIssue->common.doneCond), NULL );");
     output.println("     seseToIssue->common.doneExecuting = FALSE;");    
@@ -3346,8 +3377,27 @@ public class BuildCode {
 
                        Set<Long> allocSet = graph.getAllocationSiteIDSetBySESEID(fsen
                                        .getIdentifier());
+                       Set<Integer> connectedSet=graph.getConnectedConflictNodeSet(fsen
+                                       .getIdentifier());
+                       
                        if (allocSet.size() > 0) {
                                output.println("     {");
+                               
+                               //
+                               output.println("     ConflictNode* node;");
+                               for (Iterator iterator = connectedSet.iterator(); iterator
+                                               .hasNext();) {
+                                       Integer integer = (Integer) iterator.next();
+                                       //output.print(" "+integer);
+                                       if(integer.intValue()<0){
+                                               output.println("     node=mlpCreateConflictNode(seseCaller->classID);");
+                                       }else{
+                                               output.println("     node=mlpCreateConflictNode( "+integer+" );");
+                                       }
+                                       output.println("     addNewItem(seseToIssue->common.connectedList,node);");
+                               }
+                               //
+                               
                                output
                                                .println("     pthread_mutex_lock( &(parentCommon->lock) );");
 
@@ -3585,31 +3635,57 @@ public class BuildCode {
        output.println("   pthread_mutex_lock( &(___params___->common.parent->lock) );");
        output.println("   int idx;");
        output.println("   int giveCount=0;");
+       output.println("   struct Queue* launchQueue=createQueue();");
+       output.println("   struct QueueItem* nextQueueItem;");
        output.println("   for(idx = 0 ; idx < ___params___->common.parent->numRelatedAllocSites ; idx++){");
-       output.println("      if(!isEmpty(___params___->common.parent->allocSiteArray[idx].waitingQueue)){");
+       output.println("     if(!isEmpty(___params___->common.parent->allocSiteArray[idx].waitingQueue)){");
        output.println("     SESEcommon* item=peekItem(___params___->common.parent->allocSiteArray[idx].waitingQueue);");
        output.println("     if( item->classID == ___params___->common.classID ){");
        output.println("        struct QueueItem* qItem=findItem(___params___->common.parent->allocSiteArray[idx].waitingQueue,item);");
        output.println("        removeItem(___params___->common.parent->allocSiteArray[idx].waitingQueue,qItem);");
        output.println("        if( !isEmpty(___params___->common.parent->allocSiteArray[idx].waitingQueue) ){");
-       output.println("           SESEcommon* nextItem=peekItem(___params___->common.parent->allocSiteArray[idx].waitingQueue);");
-       output.println("           if(nextItem->classID==___params___->common.parent->classID){");
-       output.println("              struct QueueItem* stallItem=findItem(___params___->common.parent->allocSiteArray[idx].waitingQueue,nextItem);");
-       output.println("              removeItem(___params___->common.parent->allocSiteArray[idx].waitingQueue,stallItem);");
-       output.println("              giveCount++;");
-       output.println("           }else{");
-       output.println("              pthread_mutex_lock( &(nextItem->lock) );");
-       output.println("              --(nextItem->unresolvedDependencies);");
-       output.println("              if( nextItem->unresolvedDependencies == 0){");
-       output.println("                 workScheduleSubmit( (void*)nextItem);");
-       output.println("              }");
-       output.println("              pthread_mutex_unlock( &(nextItem->lock) );");
-       output.println("           }");
+       
+       output.println("           struct QueueItem* nextQItem=getHead(___params___->common.parent->allocSiteArray[idx].waitingQueue);");
+       output.println("           while(nextQItem!=NULL){");
+       output.println("              SESEcommon* nextItem=nextQItem->objectptr;");
+       output.println("              int isResolved=resolveWaitingQueue(___params___->common.parent->allocSiteArray[idx].waitingQueue,nextQItem);");
+       output.println("              if(nextItem->classID==___params___->common.parent->classID){");
+       output.println("                 if(isResolved){");
+       output.println("                    struct QueueItem* stallItem=findItem(___params___->common.parent->allocSiteArray[idx].waitingQueue,nextItem);");
+       output.println("                    removeItem(___params___->common.parent->allocSiteArray[idx].waitingQueue,stallItem);");
+       output.println("                    giveCount++;");
+       output.println("                 }");
+       output.println("                 if(!isEmpty(___params___->common.parent->allocSiteArray[idx].waitingQueue)){");
+//     output.println("                    nextQItem=getHead(___params___->common.parent->allocSiteArray[idx].waitingQueue);");
+       output.println("                    nextQItem=getNextQueueItem(nextQItem);");
+       output.println("                 }else{");
+       output.println("                    nextQItem=NULL;");
+       output.println("                 }");
+       output.println("              }else{");
+       output.println("                 if(isResolved){");
+       output.println("                    pthread_mutex_lock( &(nextItem->lock) );");
+       output.println("                    --(nextItem->unresolvedDependencies);");
+       output.println("                    if( nextItem->unresolvedDependencies == 0){");
+       //output.println("                       workScheduleSubmit( (void*)nextItem);");
+       output.println("                         addNewItem(launchQueue,(void*)nextItem);");
+       output.println("                    }");
+       output.println("                    pthread_mutex_unlock( &(nextItem->lock) );");
+       output.println("                 }");
+       output.println("                 nextQItem=getNextQueueItem(nextQItem);");
+       output.println("               }");
+       output.println("           } "); // end of while(nextQItem!=NULL)
        output.println("        }");
        output.println("     }");
-       output.println("     }");
+       output.println("  }");
        output.println("  }");
        output.println("  pthread_mutex_unlock( &(___params___->common.parent->lock)  );");
+       output.println("  if(!isEmpty(launchQueue)){");
+       output.println("     struct QueueItem* qItem=getHead(launchQueue);");
+       output.println("     while(qItem!=NULL){");
+       output.println("        workScheduleSubmit(qItem->objectptr);");
+       output.println("        qItem=getNextQueueItem(qItem);");
+       output.println("     }");
+       output.println("  }");
        output.println("  if(giveCount>0){");
        output.println("    psem_give(&(___params___->common.parent->memoryStallSiteSem));");
        output.println("  }");
index beea2f22b57a98c658f2f032a7755d88f0177501..b9105ff3bec498b646a5b1a839c70c7a9c4e1274 100644 (file)
@@ -39,6 +39,12 @@ AllocSite* mlpCreateAllocSiteArray(int numAllocSites){
   return newAllocSite;
 }
 
+ConflictNode* mlpCreateConflictNode(int id){
+  ConflictNode* newConflictNode=(ConflictNode*)RUNMALLOC( sizeof( ConflictNode ) );
+  newConflictNode->id=id;
+  return newConflictNode;
+}
+
 void addWaitingQueueElement(AllocSite* allocSiteArray, int numAllocSites, long allocID, void *seseRec){
 
   int i;
@@ -62,3 +68,58 @@ int getQueueIdx(AllocSite* allocSiteArray, int numAllocSites, long  allocID){
   }
   return -1;
 }
+
+int resolveWaitingQueue(struct Queue* waitingQueue,struct QueueItem* qItem){
+
+  if(!isEmpty(waitingQueue)){
+
+    SESEcommon* qCommon=qItem->objectptr;
+    
+    struct QueueItem* current=getHead(waitingQueue);
+    while(current!=NULL){
+         if(current!=qItem){
+          SESEcommon* currentCommon=current->objectptr;
+          if(hasConflicts(currentCommon->classID,qCommon->connectedList)){
+            return 0;
+          }
+        }else{
+          return 1;
+        }
+        current=getNextQueueItem(current);
+    }
+  }
+  return 1;
+}
+
+int hasConflicts(int classID, struct Queue* connectedList){
+  
+  if(!isEmpty(connectedList)){
+    struct QueueItem* queueItem=getHead(connectedList); 
+    
+    while(queueItem!=NULL){
+      ConflictNode* node=queueItem->objectptr;
+      if(node->id==classID){
+       return 1;
+      }
+      queueItem=getNextQueueItem(queueItem);      
+    }
+  }
+  return 0;
+}
+
+void addNewConflictNode(ConflictNode* node, struct Queue* connectedList){
+  
+  if(!isEmpty(connectedList)){
+    struct QueueItem* qItem=getHead(connectedList);
+    while(qItem!=NULL){
+      ConflictNode* qNode=qItem->objectptr;
+      if(qNode->id==node->id){
+       return;
+      }
+      qItem=getNextQueueItem(qItem);
+    }
+  }
+
+  addNewItem(connectedList,node);
+
+}
index 16adef36cc09a13d4987a2b744d8ab4216cabca0..99c8c426e8b1149da442b41a2fba2520e7757f7a 100644 (file)
 #define TRUE 1
 #endif
 
-// each allocation site nees the following
+// each allocation site needs the following
 typedef struct AllocSite_t{
   long id;
   struct Queue* waitingQueue;
 } AllocSite;
 
+typedef struct ConflictNode_t{
+  int id;
+} ConflictNode;
+
 // forward declaration of pointer type
 typedef struct SESEcommon_t* SESEcommon_p;
 
@@ -57,6 +61,7 @@ typedef struct SESEcommon_t {
   AllocSite* allocSiteArray;
   int numRelatedAllocSites;
   psemaphore memoryStallSiteSem;
+  struct Queue* connectedList;
 
 } SESEcommon;
 
@@ -77,6 +82,7 @@ void* mlpCreateSESErecord( int size );
 void  mlpDestroySESErecord( void* seseRecord );
 
 AllocSite* mlpCreateAllocSiteArray(int numAllocSites);
+ConflictNode* mlpCreateConflictNode(int id);
 
 
 #endif /* __MLP_RUNTIME__ */