support for optimizations later, leaf tasks need less data
authorjjenista <jjenista>
Thu, 23 Sep 2010 19:06:54 +0000 (19:06 +0000)
committerjjenista <jjenista>
Thu, 23 Sep 2010 19:06:54 +0000 (19:06 +0000)
Robust/src/Analysis/OoOJava/RBlockRelationAnalysis.java
Robust/src/IR/Flat/FlatSESEEnterNode.java

index f47d0cf1bb13ad083b0f446ac6fa00506ce8a703..73f90ced5e270fefbca8519908ddf408dfe63670 100644 (file)
@@ -40,6 +40,10 @@ public class RBlockRelationAnalysis {
                                 >
                      > fm2relmap;
 
+  // to support calculation of leaf SESEs (no children even
+  // through method calls) for optimization during code gen
+  protected Set<MethodDescriptor> methodsContainingSESEs;
+
 
   public RBlockRelationAnalysis( State     state,
                                  TypeUtil  typeUtil,
@@ -51,6 +55,8 @@ public class RBlockRelationAnalysis {
     rootSESEs = new HashSet<FlatSESEEnterNode>();
     allSESEs  = new HashSet<FlatSESEEnterNode>();
 
+    methodsContainingSESEs = new HashSet<MethodDescriptor>();
+
     fm2relmap = 
       new Hashtable< FlatMethod, Hashtable< FlatNode, Stack<FlatSESEEnterNode> > >();
 
@@ -71,6 +77,8 @@ public class RBlockRelationAnalysis {
     descriptorsToAnalyze.add( mdSourceEntry );
 
     analyzeMethods( descriptorsToAnalyze );
+
+    computeLeafSESEs();
   }
 
 
@@ -162,6 +170,7 @@ public class RBlockRelationAnalysis {
 
       if( !fsen.getIsCallerSESEplaceholder() ) {
         allSESEs.add( fsen );
+        methodsContainingSESEs.add( fm.getMethod() );
       }
 
       fsen.setfmEnclosing( fm );
@@ -197,4 +206,67 @@ public class RBlockRelationAnalysis {
       
     }
   }
+
+
+  protected void computeLeafSESEs() {
+    for( Iterator<FlatSESEEnterNode> itr = allSESEs.iterator();
+         itr.hasNext();
+         ) {
+      FlatSESEEnterNode fsen = itr.next();
+      
+      boolean hasNoNestedChildren = !fsen.getChildren().isEmpty();
+      boolean hasNoChildrenByCall = !hasChildrenByCall( fsen );
+
+      fsen.setIsLeafSESE( hasNoNestedChildren &&
+                          hasNoChildrenByCall );
+    }
+  }
+
+
+  protected boolean hasChildrenByCall( FlatSESEEnterNode fsen ) {
+
+    // visit every flat node in SESE body, find method calls that
+    // may transitively call methods with SESEs enclosed
+    Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
+    flatNodesToVisit.add( fsen );
+    
+    Set<FlatNode> visited = new HashSet<FlatNode>();    
+
+    while( !flatNodesToVisit.isEmpty() ) {
+      Iterator<FlatNode> fnItr = flatNodesToVisit.iterator();
+      FlatNode fn = fnItr.next();
+
+      flatNodesToVisit.remove( fn );
+      visited.add( fn );      
+
+      if( fn.kind() == FKind.FlatCall ) {
+        FlatCall         fc        = (FlatCall) fn;
+        MethodDescriptor mdCallee  = fc.getMethod();
+        Set              reachable = new HashSet();
+
+        reachable.addAll( callGraph.getAllMethods( mdCallee ) );
+        reachable.retainAll( methodsContainingSESEs );
+        
+        if( !reachable.isEmpty() ) {
+          return true;
+        }
+      }
+
+      if( fn == fsen.getFlatExit() ) {
+        // don't enqueue any futher nodes
+        continue;
+      }
+      
+      for( int i = 0; i < fn.numNext(); i++ ) {
+       FlatNode nn = fn.getNext( i );
+        
+       if( !visited.contains( nn ) ) {
+         flatNodesToVisit.add( nn );
+       }
+      }
+    }      
+
+    return false;
+  }
+
 }
index 086b1b769bde4284d472f792d3b5cc2034b5a283..bb33b9885f2d50a1f7cc4600f795ce300b5ba823 100644 (file)
@@ -28,6 +28,11 @@ public class FlatSESEEnterNode extends FlatNode {
   protected Integer           oldestAgeToTrack;
   protected boolean           isCallerSESEplaceholder;
 
+  protected static final int ISLEAF_UNINIT = 1;
+  protected static final int ISLEAF_FALSE  = 2;
+  protected static final int ISLEAF_TRUE   = 3;
+  protected int isLeafSESE;
+
   protected Set<FlatSESEEnterNode> children;
 
   protected Set<TempDescriptor> inVars;
@@ -98,6 +103,8 @@ public class FlatSESEEnterNode extends FlatNode {
 
     isCallerSESEplaceholder = false;
 
+    isLeafSESE = ISLEAF_UNINIT;
+
     firstDepRecField = null;
     numDepRecs       = 0;
   }
@@ -397,4 +404,22 @@ public class FlatSESEEnterNode extends FlatNode {
   public void addInVarForDynamicCoarseConflictResolution(TempDescriptor inVar) {
     inVarsForDynamicCoarseConflictResolution.add(inVar);
   }
+
+  
+  public void setIsLeafSESE( boolean isLeaf ) {
+    //protected static final int ISLEAF_UNINIT = 1;
+    if( isLeaf ) {
+      isLeafSESE = ISLEAF_TRUE;
+    } else {
+      isLeafSESE = ISLEAF_FALSE;
+    }
+  }
+
+  public boolean getIsLeafSESE() {
+    if( isLeafSESE == ISLEAF_UNINIT ) {
+      throw new Error( "isLeafSESE uninitialized" );
+    }
+
+    return isLeafSESE == ISLEAF_TRUE;
+  }
 }