successfully keep def reach info just for the store transform
[IRC.git] / Robust / src / Analysis / Disjoint / DefiniteReachAnalysis.java
index 8c1cf8b5e5af24a0e590f155360c4b37cb1a547e..f8a252ee37caa9bf9bbadd53540cf3265898b6c1 100644 (file)
@@ -13,26 +13,43 @@ public class DefiniteReachAnalysis {
   // every program point
   private Map<FlatNode, DefiniteReachState> fn2state;
 
-  private static PointerMethod pm;
+  // even though the above map has a set of nodes that
+  // have been analyzed, we need a per-intra pass set
+  // of nodes that have been analyzed, too, to filter
+  // out nodes that do not have a partial result yet
+  private Set<FlatNode> fnHasPartial;
 
-  public static void setPointerMethod( PointerMethod pm ) {
-    DefiniteReachAnalysis.pm = pm;
-  }
+
+  private static PointerMethod pm;
 
   
-  public DefiniteReachAnalysis() {
+  public DefiniteReachAnalysis( PointerMethod pm ) {
     // a class-wide initialization
     DefiniteReachState.initBuilders();
+    
+    DefiniteReachAnalysis.pm = pm;
 
-    fn2state = new HashMap<FlatNode, DefiniteReachState>();
+    fn2state     = new HashMap<FlatNode, DefiniteReachState>();
+    fnHasPartial = new HashSet<FlatNode>();
+  }
+
+
+  private void addPartialResult( FlatNode fn, DefiniteReachState state ) {
+    fn2state.put( fn, state );
+    fnHasPartial.add( fn );
   }
 
 
   public void methodEntry( FlatNode fn, 
                            Set<TempDescriptor> parameters ) {
+    // this should be called exactly once at the beginning
+    // of any intraprocedural pass, so clear partial result
+    // set
+    fnHasPartial.clear();
+
     DefiniteReachState state = makeIn( fn );
     state.methodEntry( parameters );
-    fn2state.put( fn, state );
+    addPartialResult( fn, state ); 
   }
 
   public void copy( FlatNode fn, 
@@ -40,7 +57,7 @@ public class DefiniteReachAnalysis {
                     TempDescriptor y ) {
     DefiniteReachState state = makeIn( fn );
     state.copy( x, y );
-    fn2state.put( fn, state ); 
+    addPartialResult( fn, state ); 
   }
 
   public void load( FlatNode fn, 
@@ -51,7 +68,7 @@ public class DefiniteReachAnalysis {
 
     DefiniteReachState state = makeIn( fn );
     state.load( x, y, f, edgeKeysForLoad );
-    fn2state.put( fn, state ); 
+    addPartialResult( fn, state ); 
   }
 
   public void store( FlatNode fn, 
@@ -63,14 +80,14 @@ public class DefiniteReachAnalysis {
 
     DefiniteReachState state = makeIn( fn );
     state.store( x, f, y, edgeKeysRemoved, edgeKeysAdded );
-    fn2state.put( fn, state ); 
+    addPartialResult( fn, state ); 
   }
 
   public void newObject( FlatNode fn, 
                          TempDescriptor x ) {
     DefiniteReachState state = makeIn( fn );
     state.newObject( x );
-    fn2state.put( fn, state ); 
+    addPartialResult( fn, state ); 
   }
 
   public void methodCall( FlatNode fn, 
@@ -79,11 +96,11 @@ public class DefiniteReachAnalysis {
     if( retVal != null ) {
       state.methodCall( retVal );
     }
-    fn2state.put( fn, state ); 
+    addPartialResult( fn, state ); 
   }
 
   public void otherStatement( FlatNode fn ) {
-    fn2state.put( fn, makeIn( fn ) ); 
+    addPartialResult( fn, makeIn( fn ) ); 
   }
 
 
@@ -103,10 +120,12 @@ public class DefiniteReachAnalysis {
     return state;
   }
 
+
   // get the current state for the program point just
   // before the given program point by merging the out
   // states of the predecessor statements
   public DefiniteReachState makeIn( FlatNode fn ) {
+
     if( pm.numPrev( fn ) == 0 ) {
       return new DefiniteReachState();
     }
@@ -114,8 +133,7 @@ public class DefiniteReachAnalysis {
     DefiniteReachState stateIn = null;
 
     for( int i = 0; i < pm.numPrev( fn ); ++i ) {
-
-      if( fn2state.containsKey( pm.getPrev( fn, i ) ) ) {
+      if( fnHasPartial.contains( pm.getPrev( fn, i ) ) ) {
         if( stateIn == null ) {
           // duplicate the first partial result we find
           stateIn = new DefiniteReachState( get( pm.getPrev( fn, i ) ) );