From d629847358aa257c24724f966684520bcaa3f9b6 Mon Sep 17 00:00:00 2001 From: jjenista Date: Wed, 6 May 2009 18:27:25 +0000 Subject: [PATCH] Add CodePlan object for injecting code before or after a FlatNode --- Robust/src/Analysis/MLP/CodePlan.java | 75 ++++++++++++++++++++++++ Robust/src/Analysis/MLP/MLPAnalysis.java | 49 +++++++++------- Robust/src/Makefile | 1 + Robust/src/Tests/mlp/tinyTest/test.java | 1 + 4 files changed, 105 insertions(+), 21 deletions(-) create mode 100644 Robust/src/Analysis/MLP/CodePlan.java diff --git a/Robust/src/Analysis/MLP/CodePlan.java b/Robust/src/Analysis/MLP/CodePlan.java new file mode 100644 index 00000000..8ac923b3 --- /dev/null +++ b/Robust/src/Analysis/MLP/CodePlan.java @@ -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+" }"; + } +} diff --git a/Robust/src/Analysis/MLP/MLPAnalysis.java b/Robust/src/Analysis/MLP/MLPAnalysis.java index 35626a9a..2309c29d 100644 --- a/Robust/src/Analysis/MLP/MLPAnalysis.java +++ b/Robust/src/Analysis/MLP/MLPAnalysis.java @@ -24,7 +24,7 @@ public class MLPAnalysis { private Hashtable< FlatNode, Stack > seseStacks; private Hashtable< FlatNode, Set > 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 >(); livenessVirtualReads = new Hashtable< FlatNode, Set >(); 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 stallSet = vstTable.getStallSet( currentSESE ); - TempDescriptor[] readarray=fn.readsTemps(); - for(int i=0;i readSet = vstTable.get(readtmp); - //containsAny - for(Iterator 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 readSet = vstTable.get( readtmp ); + //containsAny + for( Iterator 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 ) ); } } diff --git a/Robust/src/Makefile b/Robust/src/Makefile index 51b7b93d..4c3eeb0e 100644 --- a/Robust/src/Makefile +++ b/Robust/src/Makefile @@ -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 \ diff --git a/Robust/src/Tests/mlp/tinyTest/test.java b/Robust/src/Tests/mlp/tinyTest/test.java index cef2abe4..1593134c 100644 --- a/Robust/src/Tests/mlp/tinyTest/test.java +++ b/Robust/src/Tests/mlp/tinyTest/test.java @@ -29,5 +29,6 @@ public class Test { } x = x + 1; + y = x + 1; } } -- 2.34.1