Add CodePlan object for injecting code before or after a FlatNode
authorjjenista <jjenista>
Wed, 6 May 2009 18:27:25 +0000 (18:27 +0000)
committerjjenista <jjenista>
Wed, 6 May 2009 18:27:25 +0000 (18:27 +0000)
Robust/src/Analysis/MLP/CodePlan.java [new file with mode: 0644]
Robust/src/Analysis/MLP/MLPAnalysis.java
Robust/src/Makefile
Robust/src/Tests/mlp/tinyTest/test.java

diff --git a/Robust/src/Analysis/MLP/CodePlan.java b/Robust/src/Analysis/MLP/CodePlan.java
new file mode 100644 (file)
index 0000000..8ac923b
--- /dev/null
@@ -0,0 +1,75 @@
+package Analysis.MLP;
+
+import IR.*;
+import IR.Flat.*;
+import java.util.*;
+import java.io.*;
+
+
+// a code plan contains information based on analysis results
+// for injecting code before and/or after a flat node
+public class CodePlan {
+
+  private String before;
+  private String after;
+
+  public CodePlan( String before,
+                   String after ) {
+    this.before = before;
+    this.after  = after;
+  }
+
+  public String getBefore() {
+    return before;
+  }
+
+  public String getAfter() {
+    return after;
+  }
+
+  public boolean equals( Object o ) {
+    if( o == null ) {
+      return false;
+    }
+
+    if( !(o instanceof CodePlan) ) {
+      return false;
+    }
+
+    CodePlan cp = (CodePlan) o;
+
+    boolean beforeEq;
+    if( before == null ) {
+      beforeEq = (cp.before == null);
+    } else {
+      beforeEq = (before.equals( cp.before ));
+    }
+
+    boolean afterEq;
+    if( after == null ) {
+      afterEq = (cp.after == null);
+    } else {
+      afterEq = (after.equals( cp.after ));
+    }
+        
+    return beforeEq && afterEq;
+  }
+
+  public int hashCode() {
+    int beforeHC = 1;
+    if( before != null  ) {
+      beforeHC = before.hashCode();
+    }
+
+    int afterHC = 7;
+    if( after != null  ) {
+      afterHC = after.hashCode();
+    }
+
+    return beforeHC ^ afterHC;
+  }
+
+  public String toString() {
+    return "plan { b="+before+" a="+after+" }";
+  }
+}
index 35626a9ace90579b97fd85b84a22844ef607516f..2309c29db0a4e67656fbf687c1d58cb74a18c038 100644 (file)
@@ -24,7 +24,7 @@ public class MLPAnalysis {
   private Hashtable< FlatNode, Stack<FlatSESEEnterNode> > seseStacks;
   private Hashtable< FlatNode, Set<TempDescriptor>      > livenessVirtualReads;
   private Hashtable< FlatNode, VarSrcTokTable           > variableResults;
-  private Hashtable< FlatNode, String                   > codePlan;
+  private Hashtable< FlatNode, CodePlan                 > codePlans;
 
 
   public MLPAnalysis( State             state,
@@ -44,7 +44,7 @@ public class MLPAnalysis {
     seseStacks           = new Hashtable< FlatNode, Stack<FlatSESEEnterNode> >();
     livenessVirtualReads = new Hashtable< FlatNode, Set<TempDescriptor>      >();
     variableResults      = new Hashtable< FlatNode, VarSrcTokTable           >();
-    codePlan             = new Hashtable< FlatNode, String                   >();
+    codePlans            = new Hashtable< FlatNode, CodePlan                 >();
 
 
     // build an implicit root SESE to wrap contents of main method
@@ -524,14 +524,15 @@ public class MLPAnalysis {
     }      
 
     if( state.MLPDEBUG ) { 
-      System.out.println( fm.printMethod( codePlan ) );
+      System.out.println( fm.printMethod( codePlans ) );
     }
   }
 
   private void computeStalls_nodeActions( FlatNode fn,
                                           VarSrcTokTable vstTable,
                                           FlatSESEEnterNode currentSESE ) {
-    String s = null;
+    String before = null;
+    String after  = null;
 
     switch( fn.kind() ) {
 
@@ -545,27 +546,33 @@ public class MLPAnalysis {
 
     default: {          
       Set<VariableSourceToken> stallSet = vstTable.getStallSet( currentSESE );
-      TempDescriptor[] readarray=fn.readsTemps();
-      for(int i=0;i<readarray.length;i++) {
-         TempDescriptor readtmp=readarray[i];
-         Set<VariableSourceToken> readSet = vstTable.get(readtmp);
-         //containsAny
-         for(Iterator<VariableSourceToken> readit=readSet.iterator();readit.hasNext();) {
-             VariableSourceToken vst=readit.next();
-             if (stallSet.contains(vst)) {
-                 if (s==null)
-                     s="STALL for:";
-                 s+="("+vst+" "+readtmp+")";
-             }
-         }
-         
+      TempDescriptor[] readarray = fn.readsTemps();
+      for( int i = 0; i < readarray.length; i++ ) {
+        TempDescriptor readtmp = readarray[i];
+        Set<VariableSourceToken> readSet = vstTable.get( readtmp );
+        //containsAny
+        for( Iterator<VariableSourceToken> readit = readSet.iterator(); 
+             readit.hasNext(); ) {
+          VariableSourceToken vst = readit.next();
+          if( stallSet.contains( vst ) ) {
+            if( before == null ) {
+              before = "**STALL for:";
+            }
+            before += "("+vst+" "+readtmp+")";
+          }
+        }        
       }
     } break;
 
     } // end switch
-    if (s==null)
-       s="no op";
+    if( before == null ) {
+      before = "";
+    }
+
+    if( after == null ) {
+      after = "";
+    }
 
-    codePlan.put( fn, s );
+    codePlans.put( fn, new CodePlan( before, after ) );
   }
 }
index 51b7b93da2d9cad532b61ac049b8b654d705489f..4c3eeb0e73e40aed2510b78c70a5655d5406bcd8 100644 (file)
@@ -91,6 +91,7 @@ Analysis/MLP/MLPAnalysis.class                                                \
 Analysis/MLP/VariableSourceToken.class                                         \
 Analysis/MLP/SVKey.class                                               \
 Analysis/MLP/VarSrcTokTable.class                                      \
+Analysis/MLP/CodePlan.class                                            \
 Util/GraphNode.class Util/Namer.class Util/Relation.class              \
 Interface/HTTPHeader.class Interface/HTTPResponse.class                        \
 Interface/HTTPServices.class Interface/HashStrings.class               \
index cef2abe41f49ad9332a43d7109d89c5135b133aa..1593134c6b1a455a2ad4ee73aa6ab83d7b53bdd9 100644 (file)
@@ -29,5 +29,6 @@ public class Test {
     }
 
     x = x + 1;
+    y = x + 1;
   }
 }