From: jjenista Date: Fri, 17 Apr 2009 15:52:53 +0000 (+0000) Subject: reorganizing mlp analysis passes X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=59d2a2f40c7ed974d0d4379aaa2240dcaadc0fde;p=IRC.git reorganizing mlp analysis passes --- diff --git a/Robust/src/Analysis/MLP/MLPAnalysis.java b/Robust/src/Analysis/MLP/MLPAnalysis.java index f9c3a9ef..0ba9cacf 100644 --- a/Robust/src/Analysis/MLP/MLPAnalysis.java +++ b/Robust/src/Analysis/MLP/MLPAnalysis.java @@ -4,6 +4,7 @@ import Analysis.CallGraph.*; import Analysis.OwnershipAnalysis.*; import IR.*; import IR.Flat.*; +import IR.Tree.*; import java.util.*; import java.io.*; @@ -16,15 +17,19 @@ public class MLPAnalysis { private CallGraph callGraph; private OwnershipAnalysis ownAnalysis; - private Set seseRoots; + private Set seseRoots; + private SESENode rootTree; + private FlatSESEEnterNode rootSESE; + private FlatSESEExitNode rootExit; private Hashtable< FlatNode, Stack > seseStacks; - private Hashtable< FlatNode, VarSrcTokTable > pointResults; + private Hashtable< FlatNode, VarSrcTokTable > livenessResults; + private Hashtable< FlatNode, VarSrcTokTable > variableResults; - public MLPAnalysis( State state, - TypeUtil tu, - CallGraph callGraph, + public MLPAnalysis( State state, + TypeUtil tu, + CallGraph callGraph, OwnershipAnalysis ownAnalysis ) { @@ -36,10 +41,20 @@ public class MLPAnalysis { this.ownAnalysis = ownAnalysis; // initialize analysis data structures - seseRoots = new HashSet(); - seseStacks = new Hashtable< FlatNode, Stack >(); - pointResults = new Hashtable< FlatNode, VarSrcTokTable >(); + seseRoots = new HashSet(); + seseStacks = new Hashtable< FlatNode, Stack >(); + livenessResults = new Hashtable< FlatNode, VarSrcTokTable >(); + variableResults = new Hashtable< FlatNode, VarSrcTokTable >(); + // build an implicit root SESE to wrap contents of main method + /* + rootTree = new SESENode( "root" ); + rootSESE = new FlatSESEEnterNode( rootTree ); + rootExit = new FlatSESEExitNode ( rootTree ); + rootSESE.setFlatExit ( rootExit ); + rootExit.setFlatEnter( rootSESE ); + seseRoots.add( rootSESE ); + */ // run analysis on each method that is actually called // reachability analysis already computed this so reuse @@ -58,6 +73,10 @@ public class MLPAnalysis { // find every SESE from methods that may be called // and organize them into roots and children buildForestForward( fm ); + + if( state.MLPDEBUG ) { + printSESEForest(); + } } Iterator seseItr = seseRoots.iterator(); @@ -68,9 +87,10 @@ public class MLPAnalysis { // a child is analyzed before a parent. Start from // SESE's exit and do a backward data-flow analysis // for the source of variables - computeReadAndWriteSetBackward( fsen ); + livenessAnalysisBackward( fsen ); } + /* seseItr = seseRoots.iterator(); while( seseItr.hasNext() ) { FlatSESEEnterNode fsen = seseItr.next(); @@ -79,6 +99,7 @@ public class MLPAnalysis { // variable analysis for refinement and stalls variableAnalysisForward( fsen ); } + */ double timeEndAnalysis = (double) System.nanoTime(); double dt = (timeEndAnalysis - timeStartAnalysis)/(Math.pow( 10.0, 9.0 ) ); @@ -86,7 +107,6 @@ public class MLPAnalysis { System.out.println( treport ); } - private void buildForestForward( FlatMethod fm ) { // start from flat method top, visit every node in @@ -98,6 +118,7 @@ public class MLPAnalysis { Set visited = new HashSet(); Stack seseStackFirst = new Stack(); + //seseStackFirst.push( rootSESE ); seseStacks.put( fm, seseStackFirst ); while( !flatNodesToVisit.isEmpty() ) { @@ -110,7 +131,7 @@ public class MLPAnalysis { flatNodesToVisit.remove( fn ); visited.add( fn ); - analyzeFlatNodeForward( fn, seseStack ); + buildForest_nodeActions( fn, seseStack ); for( int i = 0; i < fn.numNext(); i++ ) { FlatNode nn = fn.getNext( i ); @@ -125,14 +146,73 @@ public class MLPAnalysis { } } + private void buildForest_nodeActions( FlatNode fn, + Stack seseStack ) { + switch( fn.kind() ) { + + case FKind.FlatSESEEnterNode: { + FlatSESEEnterNode fsen = (FlatSESEEnterNode) fn; + + if( seseStack.empty() ) { + seseRoots.add( fsen ); + } else { + seseStack.peek().addChild( fsen ); + } + seseStack.push( fsen ); + } break; + + case FKind.FlatSESEExitNode: { + FlatSESEExitNode fsexn = (FlatSESEExitNode) fn; + + assert !seseStack.empty(); + FlatSESEEnterNode fsen = seseStack.pop(); + } break; + + case FKind.FlatReturnNode: { + FlatReturnNode frn = (FlatReturnNode) fn; + if( !seseStack.empty() ) { + throw new Error( "Error: return statement enclosed within "+seseStack.peek() ); + } + } break; + + } + } - private void computeReadAndWriteSetBackward( FlatSESEEnterNode fsen ) { + private void printSESEForest() { + // we are assuming an implicit root SESE in the main method + // so assert that our forest is actually a tree + assert seseRoots.size() == 1; + System.out.println( "SESE Forest:" ); + Iterator seseItr = seseRoots.iterator(); + while( seseItr.hasNext() ) { + FlatSESEEnterNode fsen = seseItr.next(); + printSESETree( fsen, 0 ); + System.out.println( "" ); + } + } + + private void printSESETree( FlatSESEEnterNode fsen, int depth ) { + for( int i = 0; i < depth; ++i ) { + System.out.print( " " ); + } + System.out.println( fsen.getPrettyIdentifier() ); + + Iterator childItr = fsen.getChildren().iterator(); + while( childItr.hasNext() ) { + FlatSESEEnterNode fsenChild = childItr.next(); + printSESETree( fsenChild, depth + 1 ); + } + } + + + private void livenessAnalysisBackward( FlatSESEEnterNode fsen ) { + // post-order traversal, so do children first Iterator childItr = fsen.getChildren().iterator(); while( childItr.hasNext() ) { FlatSESEEnterNode fsenChild = childItr.next(); - computeReadAndWriteSetBackward( fsenChild ); + livenessAnalysisBackward( fsenChild ); } // start from an SESE exit, visit nodes in reverse up to @@ -140,38 +220,42 @@ public class MLPAnalysis { // should already be analyzed and therefore can be skipped // because child SESE enter node has all necessary info Set flatNodesToVisit = new HashSet(); - FlatSESEExitNode fsexn = fsen.getFlatExit(); + flatNodesToVisit.add( fsexn ); + /* for( int i = 0; i < fsexn.numPrev(); i++ ) { FlatNode nn = fsexn.getPrev( i ); flatNodesToVisit.add( nn ); } + */ while( !flatNodesToVisit.isEmpty() ) { FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next(); flatNodesToVisit.remove( fn ); + /* if( fn.kind() == FKind.FlatSESEExitNode ) { fn = ((FlatSESEExitNode)fn).getFlatEnter(); } - - VarSrcTokTable prev = pointResults.get( fn ); + */ + + VarSrcTokTable prev = livenessResults.get( fn ); // merge sets from control flow joins VarSrcTokTable inUnion = new VarSrcTokTable(); for( int i = 0; i < fn.numNext(); i++ ) { FlatNode nn = fn.getNext( i ); - inUnion.merge( pointResults.get( nn ) ); + inUnion.merge( livenessResults.get( nn ) ); } - VarSrcTokTable curr = analyzeFlatNodeBackward( fn, inUnion, fsen ); + VarSrcTokTable curr = liveness_nodeActions( fn, inUnion, fsen ); // if a new result, schedule backward nodes for analysis if( !curr.equals( prev ) ) { - pointResults.put( fn, curr ); + livenessResults.put( fn, curr ); - // don't flow backwards past SESE enter + // don't flow backwards past current SESE enter if( !fn.equals( fsen ) ) { for( int i = 0; i < fn.numPrev(); i++ ) { FlatNode nn = fn.getPrev( i ); @@ -181,53 +265,87 @@ public class MLPAnalysis { } } - fsen.addInVarSet( pointResults.get( fsen ).get() ); - + fsen.addInVarSet( livenessResults.get( fsen ).get() ); + if( state.MLPDEBUG ) { System.out.println( "SESE "+fsen.getPrettyIdentifier()+" has in-set:" ); Iterator tItr = fsen.getInVarSet().iterator(); while( tItr.hasNext() ) { System.out.println( " "+tItr.next() ); } + /* System.out.println( "and out-set:" ); tItr = fsen.getOutVarSet().iterator(); while( tItr.hasNext() ) { System.out.println( " "+tItr.next() ); } + */ System.out.println( "" ); } } + private VarSrcTokTable liveness_nodeActions( FlatNode fn, + VarSrcTokTable vstTable, + FlatSESEEnterNode currentSESE ) { + switch( fn.kind() ) { - private void variableAnalysisForward( FlatSESEEnterNode fsen ) { + case FKind.FlatSESEEnterNode: { + FlatSESEEnterNode fsen = (FlatSESEEnterNode) fn; + // only age if this is a child SESE, not the current + if( !fsen.equals( currentSESE ) ) { + vstTable = vstTable.age( currentSESE ); + } + } break; + + default: { + // handle effects of statement in reverse, writes then reads + TempDescriptor [] writeTemps = fn.writesTemps(); + for( int i = 0; i < writeTemps.length; ++i ) { + vstTable.remove( writeTemps[i] ); + currentSESE.addOutVar( new VariableSourceToken( currentSESE, + writeTemps[i], + new Integer( 0 ) ) ); + } + + TempDescriptor [] readTemps = fn.readsTemps(); + for( int i = 0; i < readTemps.length; ++i ) { + vstTable.add( new VariableSourceToken( currentSESE, + readTemps[i], + new Integer( 0 ) ) ); + } + } break; + + } // end switch + + return vstTable; + } + + + private void variableAnalysisForward( FlatSESEEnterNode fsen ) { + Set flatNodesToVisit = new HashSet(); flatNodesToVisit.add( fsen ); - /* while( !flatNodesToVisit.isEmpty() ) { FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next(); flatNodesToVisit.remove( fn ); - if( fn.kind() == FKind.FlatSESEExitNode ) { - fn = ((FlatSESEExitNode)fn).getFlatEnter(); - } - - VarSrcTokTable prev = pointResults.get( fn ); + VarSrcTokTable prev = variableResults.get( fn ); // merge sets from control flow joins VarSrcTokTable inUnion = new VarSrcTokTable(); - for( int i = 0; i < fn.numNext(); i++ ) { - FlatNode nn = fn.getNext( i ); - inUnion.merge( pointResults.get( nn ) ); + for( int i = 0; i < fn.numPrev(); i++ ) { + FlatNode nn = fn.getPrev( i ); + inUnion.merge( variableResults.get( nn ) ); } - VarSrcTokTable curr = analyzeFlatNodeBackward( fn, inUnion, fsen ); + VarSrcTokTable curr = variable_nodeActions( fn, inUnion, fsen ); // if a new result, schedule backward nodes for analysis if( !curr.equals( prev ) ) { - pointResults.put( fn, curr ); + variableResults.put( fn, curr ); // don't flow backwards past SESE enter if( !fn.equals( fsen ) ) { @@ -239,7 +357,7 @@ public class MLPAnalysis { } } - fsen.addInVarSet( pointResults.get( fsen ).get() ); + fsen.addInVarSet( variableResults.get( fsen ).get() ); if( state.MLPDEBUG ) { System.out.println( "SESE "+fsen.getPrettyIdentifier()+" has in-set:" ); @@ -254,76 +372,15 @@ public class MLPAnalysis { } System.out.println( "" ); } - */ - } - - - private void analyzeFlatNodeForward( FlatNode fn, - Stack seseStack ) { - switch( fn.kind() ) { - - case FKind.FlatSESEEnterNode: { - FlatSESEEnterNode fsen = (FlatSESEEnterNode) fn; - - if( seseStack.empty() ) { - seseRoots.add( fsen ); - } else { - seseStack.peek().addChild( fsen ); - } - seseStack.push( fsen ); - } break; - - case FKind.FlatSESEExitNode: { - FlatSESEExitNode fsexn = (FlatSESEExitNode) fn; - - assert !seseStack.empty(); - FlatSESEEnterNode fsen = seseStack.pop(); - } break; - - case FKind.FlatReturnNode: { - FlatReturnNode frn = (FlatReturnNode) fn; - if( !seseStack.empty() ) { - throw new Error( "Error: return statement enclosed within "+seseStack.peek() ); - } - } break; - - } } - - private VarSrcTokTable analyzeFlatNodeBackward( FlatNode fn, - VarSrcTokTable vstTable, - FlatSESEEnterNode currentSESE ) { + private VarSrcTokTable variable_nodeActions( FlatNode fn, + VarSrcTokTable vstTable, + FlatSESEEnterNode currentSESE ) { switch( fn.kind() ) { - case FKind.FlatSESEEnterNode: { - FlatSESEEnterNode fsen = (FlatSESEEnterNode) fn; - //vstTable.addAll( fsen.getInVarSet() ); - vstTable = vstTable.age( currentSESE ); - } break; - - case FKind.FlatSESEExitNode: { - FlatSESEExitNode fsexn = (FlatSESEExitNode) fn; - - //FlatSESEEnterNode fsen = fsexn.getFlatEnter(); - } break; default: { - // handle effects of statement in reverse, writes then reads - TempDescriptor [] writeTemps = fn.writesTemps(); - for( int i = 0; i < writeTemps.length; ++i ) { - vstTable.remove( writeTemps[i] ); - currentSESE.addOutVar( new VariableSourceToken( currentSESE, - writeTemps[i], - new Integer( 0 ) ) ); - } - - TempDescriptor [] readTemps = fn.readsTemps(); - for( int i = 0; i < readTemps.length; ++i ) { - vstTable.add( new VariableSourceToken( currentSESE, - readTemps[i], - new Integer( 0 ) ) ); - } } break; } // end switch diff --git a/Robust/src/Analysis/MLP/VarSrcTokTable.java b/Robust/src/Analysis/MLP/VarSrcTokTable.java index dac2cfc0..e1a20253 100644 --- a/Robust/src/Analysis/MLP/VarSrcTokTable.java +++ b/Robust/src/Analysis/MLP/VarSrcTokTable.java @@ -19,6 +19,9 @@ public class VarSrcTokTable { private Hashtable< TempDescriptor, Set > var2vst; private Hashtable< SVKey, Set > sv2vst; + // maximum age from aging operation + private Integer MAX_AGE = new Integer( 2 ); + public VarSrcTokTable() { trueSet = new HashSet(); @@ -213,14 +216,18 @@ public class VarSrcTokTable { while( itr.hasNext() ) { VariableSourceToken vst = itr.next(); if( vst.getSESE().equals( curr ) ) { + Integer newAge = vst.getAge()+1; + if( newAge > MAX_AGE ) { + newAge = MAX_AGE; + } out.add( new VariableSourceToken( curr, vst.getVar(), - vst.getAge()+1 ) ); + newAge ) ); } else { assert curr.getChildren().contains( vst.getSESE() ); out.add( new VariableSourceToken( curr, vst.getVar(), - new Integer( 0 ) ) ); + new Integer( 1 ) ) ); } } diff --git a/Robust/src/Tests/mlp/tinyTest/test.java b/Robust/src/Tests/mlp/tinyTest/test.java index dd09c80a..5a6a6a8a 100644 --- a/Robust/src/Tests/mlp/tinyTest/test.java +++ b/Robust/src/Tests/mlp/tinyTest/test.java @@ -4,20 +4,23 @@ public class Test { // no code is outside the root sese // in the main method sese root { + int n = 10; sese top { int x = 0; - for( int i = 0; i < 3; ++i ) { + + //for( int i = 0; i < 3; ++i ) { sese iter { - x = x + i; + x = x; // + i; } - } + //} + int j = x + n; } - + int z = n + j; } }