a better workscheduler--still has a deficiency because it does not dynamically create...
[IRC.git] / Robust / src / Analysis / MLP / MLPAnalysis.java
index 6766027ea28291fb09cb97a0424682581a068295..4fa426014d619d5291e4e91db8884914c047a3f2 100644 (file)
@@ -158,7 +158,7 @@ public class MLPAnalysis {
       notAvailableForward( fm );
     }
     if( state.MLPDEBUG ) {      
-      System.out.println( "\nNot Available Results-Out\n---------------------\n"+fmMain.printMethod( notAvailableResults ) );
+      //System.out.println( "\nNot Available Results-Out\n---------------------\n"+fmMain.printMethod( notAvailableResults ) );
     }
 
 
@@ -172,10 +172,9 @@ public class MLPAnalysis {
       computeStallsForward( fm );
     }
     if( state.MLPDEBUG ) {
-      System.out.println( "\nCode Plans\n----------\n"+fmMain.printMethod( codePlans ) );
+      //System.out.println( "\nCode Plans\n----------\n"+fmMain.printMethod( codePlans ) );
     }
 
-
     // splice new IR nodes into graph after all
     // analysis passes are complete
     Iterator spliceItr = wdvNodesToSpliceIn.entrySet().iterator();
@@ -185,6 +184,10 @@ public class MLPAnalysis {
       fwdvn.spliceIntoIR();
     }
 
+    // detailed per-SESE information
+    if( state.MLPDEBUG ) {
+      System.out.println( "\nSESE info\n-------------\n" ); printSESEInfo();
+    }
 
     double timeEndAnalysis = (double) System.nanoTime();
     double dt = (timeEndAnalysis - timeStartAnalysis)/(Math.pow( 10.0, 9.0 ) );
@@ -447,6 +450,49 @@ public class MLPAnalysis {
     }
   }
 
+  private void printSESEInfo() {
+    printSESEInfoTree( rootSESE );
+    System.out.println( "" );
+  }
+
+  private void printSESEInfoTree( FlatSESEEnterNode fsen ) {
+
+    System.out.println( "SESE "+fsen.getPrettyIdentifier()+" {" );
+
+    System.out.println( "  in-set: "+fsen.getInVarSet() );
+    Iterator<TempDescriptor> tItr = fsen.getInVarSet().iterator();
+    while( tItr.hasNext() ) {
+      TempDescriptor inVar = tItr.next();
+      if( fsen.getReadyInVarSet().contains( inVar ) ) {
+       System.out.println( "    (ready)  "+inVar );
+      }
+      if( fsen.getStaticInVarSet().contains( inVar ) ) {
+       System.out.println( "    (static) "+inVar );
+      } 
+      if( fsen.getDynamicInVarSet().contains( inVar ) ) {
+       System.out.println( "    (dynamic)"+inVar );
+      }
+    }
+
+    System.out.println( "  out-set: "+fsen.getOutVarSet() );
+
+    /*
+    System.out.println( "  static names to track:" );
+    tItr = fsen.getOutVarSet().iterator();
+    while( tItr.hasNext() ) {
+      System.out.println( "    "+tItr.next() );
+    }
+    */
+
+    System.out.println( "}" );
+
+    Iterator<FlatSESEEnterNode> childItr = fsen.getChildren().iterator();
+    while( childItr.hasNext() ) {
+      FlatSESEEnterNode fsenChild = childItr.next();
+      printSESEInfoTree( fsenChild );
+    }
+  }
+
 
   private void variableAnalysisForward( FlatMethod fm ) {
 
@@ -494,8 +540,12 @@ public class MLPAnalysis {
     case FKind.FlatSESEEnterNode: {
       FlatSESEEnterNode fsen = (FlatSESEEnterNode) fn;
       assert fsen.equals( currentSESE );
+
       vstTable.age( currentSESE );
       vstTable.assertConsistency();
+
+      vstTable.ownInSet( currentSESE );
+      vstTable.assertConsistency();
     } break;
 
     case FKind.FlatSESEExitNode: {
@@ -738,8 +788,8 @@ public class MLPAnalysis {
         TempDescriptor rTemp = readTemps[i];
         notAvailSet.remove( rTemp );
 
-       // if this variable has exactly one source, mark everything
-       // else from that source as available as well
+       // if this variable has exactly one source, potentially
+       // get other things from this source as well
        VarSrcTokTable vstTable = variableResults.get( fn );
 
        Integer srcType = 
@@ -754,9 +804,25 @@ public class MLPAnalysis {
          Iterator<VariableSourceToken> availItr = vstTable.get( vst.getSESE(),
                                                                 vst.getAge()
                                                                 ).iterator();
+
+         // look through things that are also available from same source
          while( availItr.hasNext() ) {
            VariableSourceToken vstAlsoAvail = availItr.next();
-           notAvailSet.removeAll( vstAlsoAvail.getRefVars() );
+         
+           Iterator<TempDescriptor> refVarItr = vstAlsoAvail.getRefVars().iterator();
+           while( refVarItr.hasNext() ) {
+             TempDescriptor refVarAlso = refVarItr.next();
+
+             // if a variable is available from the same source, AND it ALSO
+             // only comes from one statically known source, mark it available
+             Integer srcTypeAlso = 
+               vstTable.getRefVarSrcType( refVarAlso, 
+                                          currentSESE,
+                                          currentSESE.getParent() );
+             if( srcTypeAlso.equals( VarSrcTokTable.SrcType_STATIC ) ) {
+               notAvailSet.remove( refVarAlso );
+             }
+           }
          }
        }
       }
@@ -803,8 +869,15 @@ public class MLPAnalysis {
         }
       }
 
+      Set<TempDescriptor> dotSTlive = livenessRootView.get( fn );
+
       if( !seseStack.empty() ) {
-       computeStalls_nodeActions( fn, dotSTtable, dotSTnotAvailSet, seseStack.peek() );
+       computeStalls_nodeActions( fn, 
+                                  dotSTlive,
+                                  dotSTtable,
+                                  dotSTnotAvailSet,
+                                  seseStack.peek()
+                                  );
       }
 
       for( int i = 0; i < fn.numNext(); i++ ) {
@@ -818,11 +891,12 @@ public class MLPAnalysis {
   }
 
   private void computeStalls_nodeActions( FlatNode fn,
-                                          VarSrcTokTable vstTable,
-                                         Set<TempDescriptor> notAvailSet,
+                                         Set<TempDescriptor> liveSetIn,
+                                          VarSrcTokTable vstTableIn,
+                                         Set<TempDescriptor> notAvailSetIn,
                                           FlatSESEEnterNode currentSESE ) {
-    CodePlan plan = new CodePlan();
 
+    CodePlan plan = new CodePlan( currentSESE);
 
     switch( fn.kind() ) {
 
@@ -836,16 +910,19 @@ public class MLPAnalysis {
       while( inVarItr.hasNext() ) {
        TempDescriptor inVar = inVarItr.next();
        Integer srcType = 
-         vstTable.getRefVarSrcType( inVar, 
-                                    fsen,
-                                    fsen.getParent() );
+         vstTableIn.getRefVarSrcType( inVar, 
+                                      fsen,
+                                      fsen.getParent() );
 
+       // the current SESE needs a local space to track the dynamic
+       // variable and the child needs space in its SESE record
        if( srcType.equals( VarSrcTokTable.SrcType_DYNAMIC ) ) {
          fsen.addDynamicInVar( inVar );
+         fsen.getParent().addDynamicVar( inVar );
 
        } else if( srcType.equals( VarSrcTokTable.SrcType_STATIC ) ) {
          fsen.addStaticInVar( inVar );
-         VariableSourceToken vst = vstTable.get( inVar ).iterator().next();
+         VariableSourceToken vst = vstTableIn.get( inVar ).iterator().next();
          fsen.putStaticInVar2src( inVar, vst );
          fsen.addStaticInVarSrc( new SESEandAgePair( vst.getSESE(), 
                                                      vst.getAge() 
@@ -868,9 +945,26 @@ public class MLPAnalysis {
       FlatOpNode fon = (FlatOpNode) fn;
 
       if( fon.getOp().getOp() == Operation.ASSIGN ) {
+       TempDescriptor lhs = fon.getDest();
+       TempDescriptor rhs = fon.getLeft();        
+
        // if this is an op node, don't stall, copy
        // source and delay until we need to use value
 
+       // but check the source type of rhs variable
+       // and if dynamic, lhs becomes dynamic, too,
+       // and we need to keep dynamic sources during
+       Integer srcType 
+         = vstTableIn.getRefVarSrcType( rhs,
+                                        currentSESE,
+                                        currentSESE.getParent() );
+
+       if( srcType.equals( VarSrcTokTable.SrcType_DYNAMIC ) ) {
+         plan.addDynAssign( lhs, rhs );
+         currentSESE.addDynamicVar( lhs );
+         currentSESE.addDynamicVar( rhs );
+       }
+
        // only break if this is an ASSIGN op node,
        // otherwise fall through to default case
        break;
@@ -882,8 +976,7 @@ public class MLPAnalysis {
     default: {          
 
       // a node with no live set has nothing to stall for
-      Set<TempDescriptor> liveSet = livenessRootView.get( fn );
-      if( liveSet == null ) {
+      if( liveSetIn == null ) {
        break;
       }
 
@@ -893,38 +986,34 @@ public class MLPAnalysis {
 
        // ignore temps that are definitely available 
        // when considering to stall on it
-       if( !notAvailSet.contains( readtmp ) ) {
+       if( !notAvailSetIn.contains( readtmp ) ) {
          continue;
        }
 
        // check the source type of this variable
        Integer srcType 
-         = vstTable.getRefVarSrcType( readtmp,
+         = vstTableIn.getRefVarSrcType( readtmp,
                                       currentSESE,
                                       currentSESE.getParent() );
 
-
-       System.out.println( "considering stall on "+readtmp+" for "+currentSESE );
-
        if( srcType.equals( VarSrcTokTable.SrcType_DYNAMIC ) ) {
          // 1) It is not clear statically where this variable will
          // come from statically, so dynamically we must keep track
          // along various control paths, and therefore when we stall,
          // just stall for the exact thing we need and move on
          plan.addDynamicStall( readtmp );
-         currentSESE.addDynamicStallVar( readtmp );
-         System.out.println( "ADDING "+readtmp+" TO "+currentSESE+" DYNSTALLSET" );
-         
+         currentSESE.addDynamicVar( readtmp );
+
        } else if( srcType.equals( VarSrcTokTable.SrcType_STATIC ) ) {    
          // 2) Single token/age pair: Stall for token/age pair, and copy
          // all live variables with same token/age pair at the same
          // time.  This is the same stuff that the notavaialable analysis 
          // marks as now available.      
 
-         VariableSourceToken vst = vstTable.get( readtmp ).iterator().next();
+         VariableSourceToken vst = vstTableIn.get( readtmp ).iterator().next();
 
          Iterator<VariableSourceToken> availItr = 
-           vstTable.get( vst.getSESE(), vst.getAge() ).iterator();
+           vstTableIn.get( vst.getSESE(), vst.getAge() ).iterator();
 
          while( availItr.hasNext() ) {
            VariableSourceToken vstAlsoAvail = availItr.next();
@@ -935,7 +1024,7 @@ public class MLPAnalysis {
            Iterator<TempDescriptor> refVarItr = vstAlsoAvail.getRefVars().iterator();
            while( refVarItr.hasNext() ) {
              TempDescriptor refVar = refVarItr.next();
-             if( liveSet.contains( refVar ) ) {
+             if( liveSetIn.contains( refVar ) ) {
                copySet.add( refVar );
              }
            }
@@ -959,13 +1048,13 @@ public class MLPAnalysis {
 
       }      
     } break;
-
+      
     } // end switch
 
 
     // identify sese-age pairs that are statically useful
     // and should have an associated SESE variable in code
-    Set<VariableSourceToken> staticSet = vstTable.getStaticSet();
+    Set<VariableSourceToken> staticSet = vstTableIn.getStaticSet();
     Iterator<VariableSourceToken> vstItr = staticSet.iterator();
     while( vstItr.hasNext() ) {
       VariableSourceToken vst = vstItr.next();
@@ -979,19 +1068,21 @@ public class MLPAnalysis {
     codePlans.put( fn, plan );
 
 
-    // if any variables at this node have a static source (exactly one vst)
-    // but go to a dynamic source at a next node, create a new IR graph
+    // if any variables at this-node-*dot* have a static source (exactly one vst)
+    // but go to a dynamic source at next-node-*dot*, create a new IR graph
     // node on that edge to track the sources dynamically
+    VarSrcTokTable thisVstTable = variableResults.get( fn );
     for( int i = 0; i < fn.numNext(); i++ ) {
-      FlatNode nn = fn.getNext( i );
-      VarSrcTokTable nextVstTable = variableResults.get( nn );
+      FlatNode            nn           = fn.getNext( i );
+      VarSrcTokTable      nextVstTable = variableResults.get( nn );
+      Set<TempDescriptor> nextLiveIn   = livenessRootView.get( nn );
 
       // the table can be null if it is one of the few IR nodes
       // completely outside of the root SESE scope
-      if( nextVstTable != null ) {
+      if( nextVstTable != null && nextLiveIn != null ) {
 
        Hashtable<TempDescriptor, VariableSourceToken> static2dynamicSet = 
-         vstTable.getStatic2DynamicSet( nextVstTable );
+         thisVstTable.getStatic2DynamicSet( nextVstTable, nextLiveIn );
        
        if( !static2dynamicSet.isEmpty() ) {
 
@@ -1001,7 +1092,11 @@ public class MLPAnalysis {
          FlatWriteDynamicVarNode fwdvn = wdvNodesToSpliceIn.get( fe );
 
          if( fwdvn == null ) {
-           fwdvn = new FlatWriteDynamicVarNode( fn, nn, static2dynamicSet );
+           fwdvn = new FlatWriteDynamicVarNode( fn, 
+                                                nn,
+                                                static2dynamicSet,
+                                                currentSESE
+                                                );
            wdvNodesToSpliceIn.put( fe, fwdvn );
          } else {
            fwdvn.addMoreVar2Src( static2dynamicSet );