import java.io.BufferedWriter;
import java.io.FileWriter;
+import java.util.Collection;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
}
}
}
+
}
if (readEffectsSet != null) {
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) {
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()));
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;");
output.println(" }");
}
}
+ }
}
switch(fn.kind()) {
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;");
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) );");
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(" }");
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;
}
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);
+
+}