--- /dev/null
+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+" }";
+ }
+}
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,
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
}
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() ) {
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 ) );
}
}