primitive dynamic variables are working
authorjjenista <jjenista>
Thu, 13 Aug 2009 19:16:41 +0000 (19:16 +0000)
committerjjenista <jjenista>
Thu, 13 Aug 2009 19:16:41 +0000 (19:16 +0000)
Robust/src/Analysis/MLP/CodePlan.java
Robust/src/Analysis/MLP/MLPAnalysis.java
Robust/src/Analysis/MLP/VarSrcTokTable.java
Robust/src/IR/Flat/BuildCode.java
Robust/src/IR/Flat/FlatSESEEnterNode.java
Robust/src/IR/Flat/FlatWriteDynamicVarNode.java
Robust/src/Tests/mlp/tinyTest/test.java

index d71626e8106e50a61d04d03bd43bb9218a49d861..28b08f8c1aa34dafc639292aa7f1701301328252 100644 (file)
@@ -11,12 +11,13 @@ import java.io.*;
 public class CodePlan {
     
   private Hashtable< VariableSourceToken, Set<TempDescriptor> > stall2copySet;
-  private Set<TempDescriptor> dynamicStallSet;
-
+  private Set<TempDescriptor>                                   dynamicStallSet;
+  private Hashtable<TempDescriptor, TempDescriptor>             dynAssign_lhs2rhs;
   
   public CodePlan() {
-    stall2copySet = new Hashtable< VariableSourceToken, Set<TempDescriptor> >();
-    dynamicStallSet = new HashSet<TempDescriptor>();
+    stall2copySet     = new Hashtable< VariableSourceToken, Set<TempDescriptor> >();
+    dynamicStallSet   = new HashSet<TempDescriptor>();
+    dynAssign_lhs2rhs = new Hashtable<TempDescriptor, TempDescriptor>();
   }
 
   
@@ -48,6 +49,14 @@ public class CodePlan {
     return dynamicStallSet;
   }
 
+  public void addDynAssign( TempDescriptor lhs,
+                           TempDescriptor rhs ) {
+    dynAssign_lhs2rhs.put( lhs, rhs );
+  }
+
+  public Hashtable<TempDescriptor, TempDescriptor> getDynAssigns() {
+    return dynAssign_lhs2rhs;
+  }
 
   public boolean equals( Object o ) {
     if( o == null ) {
@@ -63,8 +72,10 @@ public class CodePlan {
     boolean copySetsEq = (stall2copySet.equals( cp.stall2copySet ));
 
     boolean dynStallSetEq = (dynamicStallSet.equals( cp.dynamicStallSet ));
+
+    boolean dynAssignEq = (dynAssign_lhs2rhs.equals( cp.dynAssign_lhs2rhs ));
         
-    return copySetsEq && dynStallSetEq;
+    return copySetsEq && dynStallSetEq && dynAssignEq;
   }
 
   public int hashCode() {
@@ -73,9 +84,12 @@ public class CodePlan {
 
     int dynStallSetHC = dynamicStallSet.hashCode();
 
+    int dynAssignHC = dynAssign_lhs2rhs.hashCode();
+
     int hash = 7;
     hash = 31*hash + copySetsHC;
     hash = 31*hash + dynStallSetHC;
+    hash = 31*hash + dynAssignHC;
     return hash;
   }
 
@@ -101,6 +115,10 @@ public class CodePlan {
       s += "[DYN STALLS:"+dynamicStallSet+"]";
     }
 
+    if( !dynAssign_lhs2rhs.isEmpty() ) {
+      s += "[DYN ASSIGNS:"+dynAssign_lhs2rhs+"]";
+    }
+
     return s;
   }
 }
index ed72c5ac5aecbb6feb703130ce9cf13eb3a74e3f..6faa882949d475a5f7915839b166445d89a09b20 100644 (file)
@@ -143,7 +143,7 @@ public class MLPAnalysis {
       pruneVariableResultsWithLiveness( fm );
     }
     if( state.MLPDEBUG ) {      
-      System.out.println( "\nVariable Results-Out\n----------------\n"+fmMain.printMethod( variableResults ) );
+      //System.out.println( "\nVariable Results-Out\n----------------\n"+fmMain.printMethod( variableResults ) );
     }
     
 
@@ -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 ) );
     }
 
 
@@ -823,8 +823,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++ ) {
@@ -838,8 +845,9 @@ 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();
 
@@ -856,7 +864,7 @@ public class MLPAnalysis {
       while( inVarItr.hasNext() ) {
        TempDescriptor inVar = inVarItr.next();
        Integer srcType = 
-         vstTable.getRefVarSrcType( inVar, 
+         vstTableIn.getRefVarSrcType( inVar, 
                                     fsen,
                                     fsen.getParent() );
 
@@ -865,7 +873,7 @@ public class MLPAnalysis {
 
        } 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() 
@@ -888,9 +896,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;
@@ -902,8 +927,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;
       }
 
@@ -913,13 +937,13 @@ 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() );
 
@@ -929,7 +953,7 @@ public class MLPAnalysis {
          // 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 );
+         currentSESE.addDynamicVar( readtmp );
          
        } else if( srcType.equals( VarSrcTokTable.SrcType_STATIC ) ) {    
          // 2) Single token/age pair: Stall for token/age pair, and copy
@@ -937,10 +961,10 @@ public class MLPAnalysis {
          // 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();
@@ -951,7 +975,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 );
              }
            }
@@ -975,13 +999,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();
@@ -995,19 +1019,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() ) {
 
@@ -1017,7 +1043,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 );
index 0b07adbe0821be31b41a711a9e0e03db735766eb..bb48bc5bd238b8d302bce72b7651e46a140301dc 100644 (file)
@@ -484,7 +484,9 @@ public class VarSrcTokTable {
   // given a table from a subsequent program point, decide
   // which variables are going from a static source to a
   // dynamic source and return them
-  public Hashtable<TempDescriptor, VariableSourceToken> getStatic2DynamicSet( VarSrcTokTable next ) {
+  public Hashtable<TempDescriptor, VariableSourceToken> 
+    getStatic2DynamicSet( VarSrcTokTable nextTable,
+                         Set<TempDescriptor> nextLiveIn ) {
     
     Hashtable<TempDescriptor, VariableSourceToken> out = 
       new Hashtable<TempDescriptor, VariableSourceToken>();
@@ -495,19 +497,23 @@ public class VarSrcTokTable {
       TempDescriptor               var = (TempDescriptor)               me.getKey();
       HashSet<VariableSourceToken> s1  = (HashSet<VariableSourceToken>) me.getValue();      
 
-      // this is a variable with a static source if it
-      // currently has one vst
-      if( s1.size() == 1 ) {
-        Set<VariableSourceToken> s2 = next.get( var );
+      // only worth tracking if live
+      if( nextLiveIn.contains( var ) ) {
 
-       // and if in the next table, it is dynamic, then
-       // this is a transition point, so
-        if( s2.size() > 1 ) {
+       // this is a variable with a static source if it
+       // currently has one vst
+       if( s1.size() == 1 ) {
+         Set<VariableSourceToken> s2 = nextTable.get( var );    
 
-         // remember the variable and the only source
-         // it had before crossing the transition
-         out.put( var, s1.iterator().next() );
-        }
+         // and if in the next table, it is dynamic, then
+         // this is a transition point, so
+         if( s2.size() > 1 ) {    
+
+           // remember the variable and the only source
+           // it had before crossing the transition
+           out.put( var, s1.iterator().next() );
+         }
+       }
       }
     }
 
index fa56edcf890f03c1a3d968ed4646ab01eddfe90b..fa42b1f0603b3b51369d7874ba81072373bb2dd7 100644 (file)
@@ -1873,20 +1873,12 @@ public class BuildCode {
     }
 
     // declare variables for tracking dynamic sources
-    Set<TempDescriptor> dynSrcVars = new HashSet<TempDescriptor>();
-    dynSrcVars.addAll( fsen.getDynamicStallVarSet() );
-    Iterator<FlatSESEEnterNode> childItr = fsen.getChildren().iterator();
-    while( childItr.hasNext() ) {
-      FlatSESEEnterNode child = childItr.next();
-      dynSrcVars.addAll( child.getDynamicInVarSet() );
-    }
-    Iterator<TempDescriptor> dynItr = dynSrcVars.iterator();
-    while( dynItr.hasNext() ) {
-      TempDescriptor dynVar = dynItr.next();
-      output.println("   void*  "+dynVar+"_srcSESE;");
-      output.println("   INTPTR "+dynVar+"_srcAddr;");
-    }
-    
+    Iterator<TempDescriptor> dynSrcItr = fsen.getDynamicVarSet().iterator();
+    while( dynSrcItr.hasNext() ) {
+      TempDescriptor dynSrcVar = dynSrcItr.next();
+      output.println("   void* "+dynSrcVar+"_srcSESE;");
+      output.println("   int   "+dynSrcVar+"_srcOffset;");
+    }    
 
     // declare local temps for in-set primitives, and if it is
     // a ready-source variable, get the value from the record
@@ -2280,14 +2272,33 @@ public class BuildCode {
 
          output.println("   }");
        }
-
        
-       // for each variable with a dynamic source, stall just
-       // for that variable
+       // for each variable with a dynamic source, stall just for that variable
        Iterator<TempDescriptor> dynItr = cp.getDynamicStallSet().iterator();
        while( dynItr.hasNext() ) {
          TempDescriptor dynVar = dynItr.next();
 
+         // only stall if the dynamic source is not yourself, denoted by src==NULL
+         // otherwise the dynamic write nodes will have the local var up-to-date
+         output.println("   {");
+         output.println("     if( "+dynVar+"_srcSESE != NULL ) {");
+         output.println("       SESEcommon* common = (SESEcommon*) "+dynVar+"_srcSESE;");
+         output.println("       psem_take( &(common->stallSem) );");
+         output.println("       "+dynVar+" = *(("+dynVar.getType()+"*) ("+
+                                               dynVar+"_srcSESE + "+dynVar+"_srcOffset));");
+         output.println("     }");
+         output.println("   }");
+       }
+
+       // for each assignment of a variable to rhs that has a dynamic source,
+       // copy the dynamic sources
+       Iterator dynAssignItr = cp.getDynAssigns().entrySet().iterator();
+       while( dynAssignItr.hasNext() ) {
+         Map.Entry      me  = (Map.Entry)      dynAssignItr.next();
+         TempDescriptor lhs = (TempDescriptor) me.getKey();
+         TempDescriptor rhs = (TempDescriptor) me.getValue();
+         output.println("   "+lhs+"_srcSESE   = "+rhs+"_srcSESE;");
+         output.println("   "+lhs+"_srcOffset = "+rhs+"_srcOffset;");
        }
       }     
     }
@@ -2908,20 +2919,27 @@ public class BuildCode {
 
     Iterator wdItr = writeDynamic.entrySet().iterator();
     while( wdItr.hasNext() ) {
-      Map.Entry           me  = (Map.Entry)           wdItr.next();
-      TempDescriptor      var = (TempDescriptor)      me.getKey();
-      VariableSourceToken vst = (VariableSourceToken) me.getValue();
+      Map.Entry           me     = (Map.Entry)           wdItr.next();
+      TempDescriptor      refVar = (TempDescriptor)      me.getKey();
+      VariableSourceToken vst    = (VariableSourceToken) me.getValue();
       
       SESEandAgePair instance = new SESEandAgePair( vst.getSESE(), vst.getAge() );
       
       output.println("   {");
-      output.println("     "+var+"_srcSESE = "+instance+";");
-      
-      output.println("     "+vst.getSESE().getSESErecordName()+"* rec = ("+
-                    vst.getSESE().getSESErecordName()+") "+
-                    instance+";");
-      
-      output.println("     "+var+"_srcAddr = (INTPTR) &(rec->"+vst.getAddrVar()+");");
+
+      if( fwdvn.getEnclosingSESE().equals( vst.getSESE() ) ) {
+       // if the src comes from this SESE, it's a method local variable,
+       // mark src pointer NULL to signify that the var is up-to-date
+       output.println("     "+vst.getAddrVar()+"_srcSESE = NULL;");
+       output.println("     "+refVar+" = "+vst.getAddrVar()+";");
+
+      } else {
+       // otherwise we track where it will come from
+       output.println("     "+vst.getAddrVar()+"_srcSESE = "+instance+";");    
+       output.println("     "+vst.getAddrVar()+"_srcOffset = (int) &((("+
+                      vst.getSESE().getSESErecordName()+"*)0)->"+vst.getAddrVar()+");");
+      }
+
       output.println("   }");
     }  
   }
index 209a59613904927d77ab96dba3ab5c8a2e842cd5..b9b00e38be41f042257d576510bbb8565be8bbf3 100644 (file)
@@ -33,7 +33,7 @@ public class FlatSESEEnterNode extends FlatNode {
   protected Set<TempDescriptor> staticInVars;
   protected Set<TempDescriptor> dynamicInVars;  
 
-  protected Set<TempDescriptor> dynamicStallVars;
+  protected Set<TempDescriptor> dynamicVars;
 
   protected Hashtable<TempDescriptor, VariableSourceToken> staticInVar2src;
   
@@ -63,7 +63,7 @@ public class FlatSESEEnterNode extends FlatNode {
     readyInVars          = new HashSet<TempDescriptor>();
     staticInVars         = new HashSet<TempDescriptor>();
     dynamicInVars        = new HashSet<TempDescriptor>();
-    dynamicStallVars     = new HashSet<TempDescriptor>();
+    dynamicVars          = new HashSet<TempDescriptor>();
 
     staticInVar2src = new Hashtable<TempDescriptor, VariableSourceToken>();
   }
@@ -237,12 +237,12 @@ public class FlatSESEEnterNode extends FlatNode {
     return dynamicInVars;
   }
 
-  public void addDynamicStallVar( TempDescriptor td ) {
-    dynamicStallVars.add( td );
+  public void addDynamicVar( TempDescriptor td ) {
+    dynamicVars.add( td );
   }
 
-  public Set<TempDescriptor> getDynamicStallVarSet() {
-    return dynamicStallVars;
+  public Set<TempDescriptor> getDynamicVarSet() {
+    return dynamicVars;
   }
 
   public void mustTrackAtLeastAge( Integer age ) {
index ac9cad81c6a4c0d877f0d4c383b8fdd556406102..53b746d3047d3c56e99192e7946fdf306971c32e 100644 (file)
@@ -15,14 +15,18 @@ public class FlatWriteDynamicVarNode extends FlatNode {
   
   protected Hashtable<TempDescriptor, VariableSourceToken> var2src;
 
+  protected FlatSESEEnterNode enclosingSESE;
+
 
   public FlatWriteDynamicVarNode( FlatNode t,
                                  FlatNode h,
-                                 Hashtable<TempDescriptor, VariableSourceToken> v2s
+                                 Hashtable<TempDescriptor, VariableSourceToken> v2s,
+                                 FlatSESEEnterNode c
                                ) {
-    tailNode = t;
-    headNode = h;
-    var2src  = v2s;
+    tailNode      = t;
+    headNode      = h;
+    var2src       = v2s;
+    enclosingSESE = c;
   }
 
   public void spliceIntoIR() {
@@ -41,6 +45,10 @@ public class FlatWriteDynamicVarNode extends FlatNode {
     return var2src;
   }
 
+  public FlatSESEEnterNode getEnclosingSESE() {
+    return enclosingSESE;
+  }
+
   public String toString() {
     return "writeDynVars "+var2src.keySet();
   }
@@ -50,7 +58,11 @@ public class FlatWriteDynamicVarNode extends FlatNode {
   }
 
   public FlatNode clone(TempMap t) {
-    return new FlatWriteDynamicVarNode( tailNode, headNode, var2src );
+    return new FlatWriteDynamicVarNode( tailNode, 
+                                       headNode, 
+                                       var2src, 
+                                       enclosingSESE 
+                                       );
   }
   public void rewriteUse(TempMap t) {
   }
index a261f8697da28c7e880fc1b6f1cb48a107bb6c6d..4dd35d9941c941c779d813c151eaa53ba3c1049d 100644 (file)
@@ -12,13 +12,11 @@ public class Test {
 
   public static void main( String args[] ) {
     
-    //int x = Integer.parseInt( args[0] );
-    //int y = Integer.parseInt( args[1] );
-    //System.out.println( "root: x="+x+", y="+y );
-    int y = 2;
+    int x = Integer.parseInt( args[0] );
+    int y = Integer.parseInt( args[1] );
+    System.out.println( "root: x="+x+", y="+y );
 
-    //if( x > 3 ) {
-    if( true ) {
+    if( x > 3 ) {
       sese fi {
        y = y + 10;
       }