state machines for traverers seem to be working for small examples
authorjjenista <jjenista>
Thu, 10 Mar 2011 22:12:05 +0000 (22:12 +0000)
committerjjenista <jjenista>
Thu, 10 Mar 2011 22:12:05 +0000 (22:12 +0000)
Robust/src/Analysis/Disjoint/BuildStateMachines.java
Robust/src/Analysis/Disjoint/Canonical.java
Robust/src/Analysis/Disjoint/DisjointAnalysis.java
Robust/src/Analysis/Disjoint/ReachGraph.java
Robust/src/Analysis/Disjoint/SMFEState.java
Robust/src/Analysis/Disjoint/StateMachineForEffects.java
Robust/src/Tests/dfj/case3/test.java

index e0d6e2efa310e73de78ec0ed16201c785e998943..d7e404f21ae8f18bdc4d6c88f75c48908230127c 100644 (file)
@@ -20,6 +20,8 @@ import IR.Flat.*;
 
 public class BuildStateMachines {
 
+  // map a task or stall site (both a FlatNode) to a variable
+  // and then finally to a state machine
   protected 
     Hashtable< FlatNode, Hashtable<TempDescriptor, StateMachineForEffects> >
     fn2var2smfe;
@@ -77,4 +79,25 @@ public class BuildStateMachines {
                           e );
     }
   }
+
+
+  public void writeStateMachines() {
+
+    Iterator<FlatNode> fnItr = fn2var2smfe.keySet().iterator();
+    while( fnItr.hasNext() ) {
+      FlatNode fn = fnItr.next();
+      
+      Hashtable<TempDescriptor, StateMachineForEffects> 
+        var2smfe = fn2var2smfe.get( fn );
+        
+      Iterator<TempDescriptor> varItr = var2smfe.keySet().iterator();
+      while( varItr.hasNext() ) {
+        TempDescriptor var = varItr.next();
+
+        StateMachineForEffects smfe = var2smfe.get( var );
+
+        smfe.writeAsDOT( "statemachine_"+fn.toString()+var.toString() );
+      }
+    }
+  }
 }
index 456b9dfeff85dcbb059f869549bad17596d3dd69..633b96e3cecddb88b0ad5a8ca016d1d8ff457e3c 100644 (file)
@@ -1572,4 +1572,52 @@ abstract public class Canonical {
     op2result.put( op, out );
     return out;
   }
+
+
+
+  // BOO, HISS! FlatNode operand does NOT extend
+  // Canonical, so we can't cache this op by its
+  // canonical arguments--THINK ABOUT A BETTER WAY!
+  public static Taint changeWhereDefined( Taint    t, 
+                                          FlatNode pp ) {
+    assert t != null;
+    assert t.isCanonical();
+
+    // never a cached result...
+    Taint out = new Taint( t.sese,
+                           t.stallSite,
+                           t.var,
+                           t.allocSite,
+                           pp,
+                           t.preds
+                           );
+    
+    out = (Taint) makeCanonical( out );
+    //op2result.put( op, out ); CRY CRY
+    return out;
+  }
+
+  // BOO, HISS! FlatNode operand does NOT extend
+  // Canonical, so we can't cache this op by its
+  // canonical arguments--THINK ABOUT A BETTER WAY!
+  public static TaintSet changeWhereDefined( TaintSet ts,
+                                             FlatNode pp ) {
+    assert ts != null;
+    assert ts.isCanonical();
+
+    // never a cached result...
+    TaintSet out = TaintSet.factory();
+    Iterator<Taint> itr = ts.iterator();
+    while( itr.hasNext() ) {
+      Taint t = itr.next();
+      out = Canonical.add( out,
+                           Canonical.changeWhereDefined( t, pp )
+                           );
+    }
+    
+    out = (TaintSet) makeCanonical( out );
+    //op2result.put( op, out ); CRY CRY
+    return out;
+  }
+
 }
index de09d5ec219607d241a04ab9050441357f7091f4..5e107d3761cac1c0158b5b7decfcca11a5aed970 100644 (file)
@@ -730,7 +730,6 @@ public class DisjointAnalysis {
 
     analysisComplete=true;
 
-
     double timeEndAnalysis = (double) System.nanoTime();
     double dt = (timeEndAnalysis - timeStartAnalysis)/(Math.pow( 10.0, 9.0 ) );
 
@@ -772,10 +771,14 @@ public class DisjointAnalysis {
                               );
         }
       }
+
+      if( state.RCR ) {
+        buildStateMachines.writeStateMachines();
+      }
+
     } catch( IOException e ) {
       throw new Error( "IO Exception while writing disjointness analysis output." );
     }
-
   }
 
 
@@ -1250,7 +1253,7 @@ public class DisjointAnalysis {
 
       if( shouldAnalysisTrack( fld.getType() ) ) {       
         // transfer func
-       rg.assignTempXEqualToTempYFieldF( lhs, rhs, fld );
+       rg.assignTempXEqualToTempYFieldF( lhs, rhs, fld, fn );
       }          
 
       // after transfer, use updated graph to
@@ -1292,7 +1295,7 @@ public class DisjointAnalysis {
 
       if( shouldAnalysisTrack( fld.getType() ) ) {
         // transfer func
-        strongUpdate = rg.assignTempXFieldFEqualToTempY( lhs, fld, rhs );
+        strongUpdate = rg.assignTempXFieldFEqualToTempY( lhs, fld, rhs, fn );
       }           
 
       // use transformed graph to do effects analysis
@@ -1331,7 +1334,7 @@ public class DisjointAnalysis {
 
       if( shouldAnalysisTrack( lhs.getType() ) ) {
         // transfer func
-       rg.assignTempXEqualToTempYFieldF( lhs, rhs, fdElement );
+       rg.assignTempXEqualToTempYFieldF( lhs, rhs, fdElement, fn );
       }
 
       // use transformed graph to do effects analysis
@@ -1377,7 +1380,7 @@ public class DisjointAnalysis {
         // transfer func, BUT
         // skip this node if it cannot create new reachability paths
         if( !arrayReferencees.doesNotCreateNewReaching( fsen ) ) {
-          rg.assignTempXFieldFEqualToTempY( lhs, fdElement, rhs );
+          rg.assignTempXFieldFEqualToTempY( lhs, fdElement, rhs, fn );
         }
       }
 
index d296bf24cd213a14fff8805cf498e5b310af36db..b17b3f01702f869c729e9d0bfb411cf5687de56e 100644 (file)
@@ -443,7 +443,10 @@ public class ReachGraph {
 
   public void assignTempXEqualToTempYFieldF( TempDescriptor  x,
                                             TempDescriptor  y,
-                                            FieldDescriptor f ) {
+                                            FieldDescriptor f,
+                                             FlatNode        currentProgramPoint
+                                             ) {
+    
     VariableNode lnX = getVariableNodeFromTemp( x );
     VariableNode lnY = getVariableNodeFromTemp( y );
 
@@ -484,6 +487,15 @@ public class ReachGraph {
          mostSpecificType( edgeHrn.getType(), 
                            hrnHrn.getType() 
                            );
+
+        TaintSet taints = Canonical.unionORpreds( edgeHrn.getTaints(),
+                                                  edgeY.getTaints()
+                                                  );
+        if( state.RCR ) {
+          // the DFJ way to generate taints changes for field statements
+          taints = Canonical.changeWhereDefined( taints,
+                                                 currentProgramPoint );
+        }
          
        RefEdge edgeNew = new RefEdge( lnX,
                                        hrnHrn,
@@ -491,7 +503,7 @@ public class ReachGraph {
                                        null,
                                        Canonical.intersection( betaY, betaHrn ),
                                        predsTrue,
-                                       Canonical.unionORpreds(edgeHrn.getTaints(),edgeY.getTaints())
+                                       taints
                                        );
 
         addEdgeOrMergeWithExisting( edgeNew );
@@ -518,7 +530,9 @@ public class ReachGraph {
   // return whether a strong update was actually effected
   public boolean assignTempXFieldFEqualToTempY( TempDescriptor  x,
                                                 FieldDescriptor f,
-                                                TempDescriptor  y ) {
+                                                TempDescriptor  y,
+                                                FlatNode        currentProgramPoint
+                                                ) {
 
     VariableNode lnX = getVariableNodeFromTemp( x );
     VariableNode lnY = getVariableNodeFromTemp( y );
@@ -646,6 +660,14 @@ public class ReachGraph {
                            hrnY.getType()
                            );  
 
+        TaintSet taints = edgeY.getTaints();
+        
+        if( state.RCR ) {
+          // the DFJ way to generate taints changes for field statements
+          taints = Canonical.changeWhereDefined( taints,
+                                                 currentProgramPoint );
+        }
+
        RefEdge edgeNew = 
           new RefEdge( hrnX,
                        hrnY,
@@ -658,7 +680,7 @@ public class ReachGraph {
                                                predsTrue
                                                ),
                        predsTrue,
-                       edgeY.getTaints()
+                       taints
                        );
 
         addEdgeOrMergeWithExisting( edgeNew );
index fee844d0130721af9eb67d827d9269a1fbb885b5..967533988b017ce4fe9ef6f52d803bca057a2ed2 100644 (file)
@@ -49,6 +49,7 @@ public class SMFEState {
     Set<SMFEState> states = e2states.get( effect );
     if( states == null ) {
       states = new HashSet<SMFEState>();
+      e2states.put( effect, states );
     }
     states.add( stateTo );
   }
index 69abb040be0d67e722f4ad8e1f640b84ce61eafa..f12aa2d618cc03a9f69de5785e236be68d22215b 100644 (file)
@@ -33,7 +33,6 @@ public class StateMachineForEffects {
   public void addEffect( FlatNode fnState,
                          Effect e ) {
 
-    assert fn2state.containsKey( fnState );
     SMFEState state = getState( fnState );
     state.addEffect( e );
   }
@@ -58,13 +57,14 @@ public class StateMachineForEffects {
     SMFEState state = fn2state.get( fn );
     if( state == null ) {
       state = new SMFEState( fn );
+      fn2state.put( fn, state );
     }
     return state;
   }
 
 
-  public void writeAsDOT() {
-    String graphName = initialState.getID().toString();
+  public void writeAsDOT( String graphName ) {
+    //String graphName = initialState.getID().toString();
     graphName = graphName.replaceAll( "[\\W]", "" );
 
     try {
index aabeb91fc3d21bea9f47eb07b9d94d8e27a7a3cf..f668253339758087c5bd57fc07586f15117ca534 100644 (file)
@@ -28,12 +28,12 @@ public class Test {
       t.f = a;
     }
 
-    genreach p1;
-
     rblock T {
       Foo x = a.f;
       Foo y = x.f;
       y.z = 1;
+
+      genreach pT;
     }
 
     rblock S {
@@ -42,6 +42,8 @@ public class Test {
         w = w.f;
       }
       w.z = 5;
+
+      genreach pS;
     }
 
     int total = 0;