Lots of bug fixes with regard to token table--table is consistent after every operati...
authorjjenista <jjenista>
Mon, 27 Apr 2009 18:50:02 +0000 (18:50 +0000)
committerjjenista <jjenista>
Mon, 27 Apr 2009 18:50:02 +0000 (18:50 +0000)
Robust/src/Analysis/MLP/MLPAnalysis.java
Robust/src/Analysis/MLP/VarSrcTokTable.java

index 4d66b51b8236212fc8e90e700f856070e96301f5..f56bf8bf5560c8040d4fece95026be6b916a6fee 100644 (file)
@@ -305,7 +305,20 @@ public class MLPAnalysis {
        inUnion.merge( variableResults.get( nn ) );
       }
 
+      // check merge results before sending
+      if( state.MLPDEBUG ) { 
+       inUnion.assertConsistency();
+      }
+
       VarSrcTokTable curr = variable_nodeActions( fn, inUnion, seseStack.peek() );
+      
+      // a sanity check after table operations before we proceed
+      if( state.MLPDEBUG ) { 
+       if( prev != null ) {
+         prev.assertConsistency();
+       }
+       curr.assertConsistency();
+      }
 
       // if a new result, schedule forward nodes for analysis
       if( !curr.equals( prev ) ) {
@@ -332,10 +345,11 @@ public class MLPAnalysis {
     } break;
 
     case FKind.FlatSESEExitNode: {
-      FlatSESEExitNode fsexn = (FlatSESEExitNode) fn;
-      assert currentSESE.getChildren().contains( fsexn.getFlatEnter() );
-      vstTable = vstTable.remapChildTokens( currentSESE );
-      vstTable = vstTable.removeParentAndSiblingTokens( currentSESE );
+      FlatSESEExitNode  fsexn = (FlatSESEExitNode)  fn;
+      FlatSESEEnterNode fsen  = fsexn.getFlatEnter();
+      assert currentSESE.getChildren().contains( fsen );
+      vstTable = vstTable.remapChildTokens( fsen );
+      vstTable = vstTable.removeParentAndSiblingTokens( fsen );
     } break;
 
     case FKind.FlatOpNode: {
@@ -460,7 +474,7 @@ public class MLPAnalysis {
       FlatSESEExitNode fsexn = (FlatSESEExitNode) fn;
     } break;
 
-    default: {
+    default: {          
       Set<VariableSourceToken> stallSet = vstTable.getStallSet( currentSESE );
       if( !stallSet.isEmpty() ) {
 
@@ -471,7 +485,9 @@ public class MLPAnalysis {
          VariableSourceToken vst = itr.next();
          s += "  "+vst.getVarLive();
        }       
-      }      
+      } 
+      
+
     } break;
 
     } // end switch
index 4eee968c55bb55e0b6bebafb98e6dd1bf4eb8104..cc1a798b06f34f79cda096d9e6a04edccc83fe72 100644 (file)
@@ -5,16 +5,18 @@ import IR.Flat.*;
 import java.util.*;\r
 import java.io.*;\r
 \r
+// This class formerly had lazy consistency properties, but\r
+// it is being changed so that the full set and the extra\r
+// hash tables to access the full set efficiently by different\r
+// elements will be consistent after EVERY operation.  Also,\r
+// a consistent assert method allows a debugger to ask whether\r
+// an operation has produced an inconsistent VarSrcTokTable.\r
 public class VarSrcTokTable {\r
-  \r
-  // the true set represents the set of (sese, variable, age)\r
-  // triples that are truly in the table\r
+\r
+  // a set of every token in the table\r
   private HashSet<VariableSourceToken> trueSet;\r
 \r
-  // these hashtables provide an efficient retreival from the\r
-  // true set.  Note that a particular triple from the quick\r
-  // look up must be checked against the true set--remove ops\r
-  // can cause the hashtables to be inconsistent to each other\r
+  // these hashtables provide an efficient retreival from the true set\r
   private Hashtable< TempDescriptor,    Set<VariableSourceToken> >  var2vst;\r
   private Hashtable< FlatSESEEnterNode, Set<VariableSourceToken> > sese2vst;\r
   private Hashtable< SVKey,             Set<VariableSourceToken> >   sv2vst;\r
@@ -38,7 +40,7 @@ public class VarSrcTokTable {
     Iterator itr; Set s;\r
 \r
     sese2vst = new Hashtable< FlatSESEEnterNode, Set<VariableSourceToken> >();\r
-    itr = sese2vst.entrySet().iterator();\r
+    itr = in.sese2vst.entrySet().iterator();\r
     while( itr.hasNext() ) {\r
       Map.Entry                    me   = (Map.Entry)                    itr.next();\r
       FlatSESEEnterNode            sese = (FlatSESEEnterNode)            me.getKey();\r
@@ -49,7 +51,7 @@ public class VarSrcTokTable {
     }\r
 \r
     var2vst = new Hashtable< TempDescriptor, Set<VariableSourceToken> >();\r
-    itr = var2vst.entrySet().iterator();\r
+    itr = in.var2vst.entrySet().iterator();\r
     while( itr.hasNext() ) {\r
       Map.Entry                    me  = (Map.Entry)                    itr.next();\r
       TempDescriptor               var = (TempDescriptor)               me.getKey();\r
@@ -60,7 +62,7 @@ public class VarSrcTokTable {
     }\r
 \r
     sv2vst = new Hashtable< SVKey, Set<VariableSourceToken> >();\r
-    itr = sv2vst.entrySet().iterator();\r
+    itr = in.sv2vst.entrySet().iterator();\r
     while( itr.hasNext() ) {\r
       Map.Entry                    me  = (Map.Entry)                    itr.next();\r
       SVKey                        key = (SVKey)                        me.getKey();\r
@@ -118,7 +120,6 @@ public class VarSrcTokTable {
       s = new HashSet<VariableSourceToken>();      \r
       sese2vst.put( sese, s );\r
     }\r
-    s.retainAll( trueSet );\r
     return s;\r
   }\r
 \r
@@ -128,7 +129,6 @@ public class VarSrcTokTable {
       s = new HashSet<VariableSourceToken>();\r
       var2vst.put( var, s );\r
     }\r
-    s.retainAll( trueSet );\r
     return s;\r
   }\r
 \r
@@ -138,17 +138,19 @@ public class VarSrcTokTable {
       s = new HashSet<VariableSourceToken>();\r
       sv2vst.put( key, s );\r
     }\r
-    s.retainAll( trueSet );\r
     return s;\r
   }\r
 \r
 \r
-  public void merge( VarSrcTokTable table ) {\r
+  public void merge( VarSrcTokTable tableIn ) {\r
 \r
-    if( table == null ) {\r
+    if( tableIn == null ) {\r
       return;\r
     }\r
 \r
+    // make a copy for modification to use in the merge\r
+    VarSrcTokTable table = new VarSrcTokTable( tableIn );\r
+\r
     trueSet.addAll( table.trueSet );\r
 \r
     Iterator itr; \r
@@ -165,7 +167,7 @@ public class VarSrcTokTable {
 \r
       if( s2 != null ) {\r
        s1.addAll( s2 );\r
-      }           \r
+      }\r
     }\r
     s = table.sese2vst.entrySet();\r
     s.removeAll( sese2vst.entrySet() );\r
@@ -207,14 +209,37 @@ public class VarSrcTokTable {
   }\r
 \r
 \r
+  // remove operations must leave the trueSet \r
+  // and the hash maps consistent!\r
+  public void remove( VariableSourceToken vst ) {\r
+    trueSet.remove( vst );\r
+    \r
+    Set<VariableSourceToken> s;\r
+\r
+    s = get( vst.getSESE() );\r
+    if( s != null ) { s.remove( vst ); }\r
+\r
+    s = get( vst.getVarLive() );\r
+    if( s != null ) { s.remove( vst ); }\r
+\r
+    s = get( new SVKey( vst.getSESE(), vst.getVarLive() ) );\r
+    if( s != null ) { s.remove( vst ); }\r
+  }\r
+\r
   public void remove( FlatSESEEnterNode sese ) {\r
     Set<VariableSourceToken> s = sese2vst.get( sese );\r
     if( s == null ) {\r
       return;\r
     }\r
     \r
-    trueSet.removeAll( s );        \r
+    trueSet.removeAll( s );\r
     sese2vst.remove( sese );\r
+\r
+    Iterator<VariableSourceToken> itr = s.iterator();\r
+    while( itr.hasNext() ) {\r
+      VariableSourceToken vst = itr.next();\r
+      remove( vst );\r
+    }\r
   }\r
 \r
   public void remove( TempDescriptor var ) {\r
@@ -225,6 +250,12 @@ public class VarSrcTokTable {
     \r
     trueSet.removeAll( s );        \r
     var2vst.remove( var );\r
+\r
+    Iterator<VariableSourceToken> itr = s.iterator();\r
+    while( itr.hasNext() ) {\r
+      VariableSourceToken vst = itr.next();\r
+      remove( vst );\r
+    }\r
   }\r
 \r
   public void remove( FlatSESEEnterNode sese,\r
@@ -238,29 +269,37 @@ public class VarSrcTokTable {
     \r
     trueSet.removeAll( s );\r
     sv2vst.remove( key );\r
-  }\r
 \r
-  public void remove( VariableSourceToken vst ) {\r
-    trueSet.remove( vst );\r
+    Iterator<VariableSourceToken> itr = s.iterator();\r
+    while( itr.hasNext() ) {\r
+      VariableSourceToken vst = itr.next();\r
+      remove( vst );\r
+    }\r
   }\r
 \r
 \r
+\r
   // return a new table based on this one and\r
   // age tokens with respect to SESE curr, where\r
-  // any child becomes curr with age 0, and any\r
-  // curr tokens increase age by 1\r
+  // any curr tokens increase age by 1\r
   public VarSrcTokTable age( FlatSESEEnterNode curr ) {\r
 \r
-    VarSrcTokTable out = new VarSrcTokTable();\r
+    // create a table to modify as a copy of this\r
+    VarSrcTokTable out = new VarSrcTokTable( this );\r
 \r
     Iterator<VariableSourceToken> itr = trueSet.iterator();\r
     while( itr.hasNext() ) {\r
       VariableSourceToken vst = itr.next();\r
+\r
       if( vst.getSESE().equals( curr ) ) {\r
+\r
        Integer newAge = vst.getAge()+1;\r
        if( newAge > MAX_AGE ) {\r
          newAge = MAX_AGE;\r
        }\r
+\r
+       out.remove( vst );\r
+\r
         out.add( new VariableSourceToken( vst.getVarLive(), \r
                                          curr,                                           \r
                                          newAge,\r
@@ -283,18 +322,20 @@ public class VarSrcTokTable {
     Iterator<FlatSESEEnterNode> childItr = curr.getChildren().iterator();\r
     if( childItr.hasNext() ) {\r
       FlatSESEEnterNode child = childItr.next();\r
-\r
+      \r
       Iterator<VariableSourceToken> vstItr = get( child ).iterator();\r
       while( vstItr.hasNext() ) {\r
         VariableSourceToken vst = vstItr.next();\r
+\r
         out.remove( vst );\r
+\r
         out.add( new VariableSourceToken( vst.getVarLive(),\r
                                           curr,\r
                                           new Integer( 0 ),\r
                                           vst.getVarLive() ) );\r
       }\r
     }\r
-\r
+    \r
     return out;    \r
   }   \r
 \r
@@ -322,10 +363,10 @@ public class VarSrcTokTable {
         out.remove_A_if_B( child, curr );\r
       }\r
     }\r
-\r
+    \r
     return out;    \r
   }\r
-\r
+  \r
   // if B is also a source for some variable, remove all entries\r
   // of A as a source for that variable\r
   protected void remove_A_if_B( FlatSESEEnterNode a, FlatSESEEnterNode b ) {\r
@@ -344,8 +385,8 @@ public class VarSrcTokTable {
   }\r
 \r
 \r
-  public Set<VariableSourceToken> getStallSet( FlatSESEEnterNode curr/*,\r
-                                                                       TempDescriptor varLive*/ ) {\r
+  public Set<VariableSourceToken> getStallSet( FlatSESEEnterNode curr/*,                                                                       TempDescriptor varLive*/ ) {\r
+\r
 \r
     Set<VariableSourceToken> out = new HashSet<VariableSourceToken>();\r
 \r
@@ -360,6 +401,41 @@ public class VarSrcTokTable {
   }\r
 \r
 \r
+  // use as an aid for debugging, where true-set is checked\r
+  // against the alternate mappings: assert that nothing is\r
+  // missing or extra in the alternates\r
+  public void assertConsistency() {\r
+\r
+    Iterator itr; \r
+    Set s;\r
+\r
+    Set<VariableSourceToken> trueSetByAlts = new HashSet<VariableSourceToken>();\r
+\r
+    itr = sese2vst.entrySet().iterator();\r
+    while( itr.hasNext() ) {\r
+      Map.Entry                    me   = (Map.Entry)                    itr.next();\r
+      FlatSESEEnterNode            sese = (FlatSESEEnterNode)            me.getKey();\r
+      HashSet<VariableSourceToken> s1   = (HashSet<VariableSourceToken>) me.getValue();      \r
+      assert s1 != null;\r
+      \r
+      // the trueSet should have all entries in s1\r
+      assert trueSet.containsAll( s1 );\r
+\r
+      // s1 should not have anything that doesn't appear in truese\r
+      Set<VariableSourceToken> sInt = (Set<VariableSourceToken>) s1.clone();\r
+      sInt.removeAll( trueSet );\r
+\r
+      assert sInt.isEmpty();\r
+\r
+      // add s1 to a running union--at the end check if trueSet has extra\r
+      trueSetByAlts.addAll( s1 );\r
+    }\r
+\r
+    // make sure trueSet isn't too big\r
+    assert trueSetByAlts.containsAll( trueSet );\r
+  }\r
+\r
+\r
   public boolean equals( Object o ) {\r
     if( o == null ) {\r
       return false;\r
@@ -382,6 +458,10 @@ public class VarSrcTokTable {
   }\r
 \r
   public String toString() {\r
+    return "trueSet ="+trueSet.toString();\r
+  }\r
+\r
+  public String toStringVerbose() {\r
     return "trueSet ="+trueSet.toString()+"\n"+\r
            "sese2vst="+sese2vst.toString()+"\n"+\r
            "var2vst ="+var2vst.toString()+"\n"+\r