private Hashtable< FlatNode, Stack<FlatSESEEnterNode> > seseStacks;
private Hashtable< FlatNode, Set<TempDescriptor> > livenessResults;
+ private Hashtable< FlatNode, Set<TempDescriptor> > livenessVirtualReads;
private Hashtable< FlatNode, VarSrcTokTable > variableResults;
private Hashtable< FlatNode, String > codePlan;
this.ownAnalysis = ownAnalysis;
// initialize analysis data structures
- seseStacks = new Hashtable< FlatNode, Stack<FlatSESEEnterNode> >();
- livenessResults = new Hashtable< FlatNode, Set<TempDescriptor> >();
- variableResults = new Hashtable< FlatNode, VarSrcTokTable >();
- codePlan = new Hashtable< FlatNode, String >();
+ seseStacks = new Hashtable< FlatNode, Stack<FlatSESEEnterNode> >();
+ livenessResults = new Hashtable< FlatNode, Set<TempDescriptor> >();
+ livenessVirtualReads = new Hashtable< FlatNode, Set<TempDescriptor> >();
+ variableResults = new Hashtable< FlatNode, VarSrcTokTable >();
+ codePlan = new Hashtable< FlatNode, String >();
// build an implicit root SESE to wrap contents of main method
}
+ // 5th pass, compute liveness contribution from
+ // virtual reads discovered in stall pass
+ livenessAnalysisBackward( rootSESE );
+
+
double timeEndAnalysis = (double) System.nanoTime();
double dt = (timeEndAnalysis - timeStartAnalysis)/(Math.pow( 10.0, 9.0 ) );
String treport = String.format( "The mlp analysis took %.3f sec.", dt );
for( int i = 0; i < readTemps.length; ++i ) {
liveIn.add( readTemps[i] );
}
+
+ Set<TempDescriptor> virtualReadTemps = livenessVirtualReads.get( fn );
+ if( virtualReadTemps != null ) {
+ Iterator<TempDescriptor> vrItr = virtualReadTemps.iterator();
+ while( vrItr.hasNext() ) {
+ liveIn.add( vrItr.next() );
+ }
+ }
} break;
} // end switch
VarSrcTokTable prev = variableResults.get( fn );
+ // to stay sane
+ if( state.MLPDEBUG ) {
+ if( prev != null ) {
+ prev.assertConsistency();
+ }
+ }
+
// merge sets from control flow joins
VarSrcTokTable inUnion = new VarSrcTokTable();
for( int i = 0; i < fn.numPrev(); i++ ) {
FlatNode nn = fn.getPrev( i );
+
inUnion.merge( variableResults.get( nn ) );
}
// a sanity check after table operations before we proceed
if( state.MLPDEBUG ) {
- if( prev != null ) {
- prev.assertConsistency();
- }
curr.assertConsistency();
}
FlatSESEExitNode fsexn = (FlatSESEExitNode) fn;
FlatSESEEnterNode fsen = fsexn.getFlatEnter();
assert currentSESE.getChildren().contains( fsen );
- vstTable = vstTable.remapChildTokens( fsen );
- vstTable = vstTable.removeParentAndSiblingTokens( fsen );
+ vstTable.remapChildTokens( fsen );
+
+ Set<TempDescriptor> liveIn = livenessResults.get( fn );
+ Set<TempDescriptor> virLiveIn = vstTable.removeParentAndSiblingTokens( fsen, liveIn );
+ Set<TempDescriptor> virLiveInNew = livenessVirtualReads.get( fn );
+ if( virLiveInNew == null ) {
+ virLiveInNew = new HashSet<TempDescriptor>();
+ }
+ virLiveInNew.addAll( virLiveIn );
+ livenessVirtualReads.put( fn, virLiveInNew );
} break;
case FKind.FlatOpNode: {
// make a copy for modification to use in the merge\r
VarSrcTokTable table = new VarSrcTokTable( tableIn );\r
\r
+\r
trueSet.addAll( table.trueSet );\r
\r
+\r
Iterator itr; \r
- Set s;\r
\r
- itr = sese2vst.entrySet().iterator();\r
+ // merge sese2vst mappings\r
+ itr = this.sese2vst.entrySet().iterator();\r
while( itr.hasNext() ) {\r
Map.Entry me = (Map.Entry) itr.next();\r
FlatSESEEnterNode sese = (FlatSESEEnterNode) me.getKey();\r
Set<VariableSourceToken> s1 = (Set<VariableSourceToken>) me.getValue();\r
- Set<VariableSourceToken> s2 = table.sese2vst.get( sese );\r
- \r
+ Set<VariableSourceToken> s2 = table.sese2vst.get( sese ); \r
assert s1 != null;\r
\r
if( s2 != null ) {\r
s1.addAll( s2 );\r
}\r
}\r
- s = table.sese2vst.entrySet();\r
- s.removeAll( sese2vst.entrySet() );\r
- sese2vst.putAll( table.sese2vst );\r
+ itr = table.sese2vst.entrySet().iterator();\r
+ while( itr.hasNext() ) {\r
+ Map.Entry me = (Map.Entry) itr.next();\r
+ FlatSESEEnterNode sese = (FlatSESEEnterNode) me.getKey();\r
+ Set<VariableSourceToken> s2 = (Set<VariableSourceToken>) me.getValue();\r
+ Set<VariableSourceToken> s1 = this.sese2vst.get( sese );\r
+ assert s2 != null;\r
\r
- itr = var2vst.entrySet().iterator();\r
+ if( s1 == null ) {\r
+ this.sese2vst.put( sese, s2 );\r
+ } \r
+ }\r
+\r
+ // merge var2vst mappings\r
+ itr = this.var2vst.entrySet().iterator();\r
while( itr.hasNext() ) {\r
Map.Entry me = (Map.Entry) itr.next();\r
TempDescriptor var = (TempDescriptor) me.getKey();\r
Set<VariableSourceToken> s1 = (Set<VariableSourceToken>) me.getValue();\r
- Set<VariableSourceToken> s2 = table.var2vst.get( var );\r
- \r
+ Set<VariableSourceToken> s2 = table.var2vst.get( var ); \r
assert s1 != null;\r
\r
if( s2 != null ) {\r
s1.addAll( s2 );\r
} \r
}\r
- s = table.var2vst.entrySet();\r
- s.removeAll( var2vst.entrySet() );\r
- var2vst.putAll( table.var2vst );\r
+ itr = table.var2vst.entrySet().iterator();\r
+ while( itr.hasNext() ) {\r
+ Map.Entry me = (Map.Entry) itr.next();\r
+ TempDescriptor var = (TempDescriptor) me.getKey();\r
+ Set<VariableSourceToken> s2 = (Set<VariableSourceToken>) me.getValue();\r
+ Set<VariableSourceToken> s1 = this.var2vst.get( var );\r
+ assert s2 != null;\r
+\r
+ if( s1 == null ) {\r
+ this.var2vst.put( var, s2 );\r
+ } \r
+ }\r
\r
- itr = sv2vst.entrySet().iterator();\r
+ // merge sv2vst mappings\r
+ itr = this.sv2vst.entrySet().iterator();\r
while( itr.hasNext() ) {\r
Map.Entry me = (Map.Entry) itr.next();\r
SVKey key = (SVKey) me.getKey();\r
Set<VariableSourceToken> s1 = (Set<VariableSourceToken>) me.getValue();\r
- Set<VariableSourceToken> s2 = table.sv2vst.get( key );\r
- \r
+ Set<VariableSourceToken> s2 = table.sv2vst.get( key ); \r
assert s1 != null;\r
\r
if( s2 != null ) {\r
s1.addAll( s2 );\r
} \r
}\r
- s = table.sv2vst.entrySet();\r
- s.removeAll( sv2vst.entrySet() );\r
- sv2vst.putAll( table.sv2vst );\r
+ itr = table.sv2vst.entrySet().iterator();\r
+ while( itr.hasNext() ) {\r
+ Map.Entry me = (Map.Entry) itr.next();\r
+ SVKey key = (SVKey) me.getKey();\r
+ Set<VariableSourceToken> s2 = (Set<VariableSourceToken>) me.getValue();\r
+ Set<VariableSourceToken> s1 = this.sv2vst.get( key );\r
+ assert s2 != null;\r
+\r
+ if( s1 == null ) {\r
+ this.sv2vst.put( key, s2 );\r
+ } \r
+ }\r
}\r
\r
\r
\r
\r
// for the given SESE, change child tokens into this parent\r
- public VarSrcTokTable remapChildTokens( FlatSESEEnterNode curr ) {\r
-\r
- // create a table to modify as a copy of this\r
- VarSrcTokTable out = new VarSrcTokTable( this );\r
+ public void remapChildTokens( FlatSESEEnterNode curr ) {\r
\r
Iterator<FlatSESEEnterNode> childItr = curr.getChildren().iterator();\r
if( childItr.hasNext() ) {\r
while( vstItr.hasNext() ) {\r
VariableSourceToken vst = vstItr.next();\r
\r
- out.remove( vst );\r
+ remove( vst );\r
\r
- out.add( new VariableSourceToken( vst.getVarLive(),\r
- curr,\r
- new Integer( 0 ),\r
- vst.getVarLive() ) );\r
+ add( new VariableSourceToken( vst.getVarLive(),\r
+ curr,\r
+ new Integer( 0 ),\r
+ vst.getVarLive() ) );\r
}\r
}\r
- \r
- return out; \r
} \r
\r
\r
// if we can get a value from the current SESE and the parent\r
// or a sibling, just getting from the current SESE suffices now\r
- public VarSrcTokTable removeParentAndSiblingTokens( FlatSESEEnterNode curr ) {\r
+ // return a set of temps that are virtually read\r
+ public Set<TempDescriptor> removeParentAndSiblingTokens( FlatSESEEnterNode curr,\r
+ Set<TempDescriptor> liveIn ) {\r
\r
- // create a table to modify as a copy of this\r
- VarSrcTokTable out = new VarSrcTokTable( this );\r
+ HashSet<TempDescriptor> virtualLiveIn = new HashSet<TempDescriptor>();\r
\r
FlatSESEEnterNode parent = curr.getParent();\r
if( parent == null ) {\r
// have no parent or siblings\r
- return out;\r
+ return virtualLiveIn;\r
} \r
\r
- out.remove_A_if_B( parent, curr );\r
+ remove_A_if_B( parent, curr, liveIn, virtualLiveIn );\r
\r
Iterator<FlatSESEEnterNode> childItr = parent.getChildren().iterator();\r
if( childItr.hasNext() ) {\r
FlatSESEEnterNode child = childItr.next();\r
\r
if( !child.equals( curr ) ) {\r
- out.remove_A_if_B( child, curr );\r
+ remove_A_if_B( child, curr, liveIn, virtualLiveIn );\r
}\r
}\r
\r
- return out; \r
+ return virtualLiveIn;\r
}\r
\r
// if B is also a source for some variable, remove all entries\r
- // of A as a source for that variable\r
- protected void remove_A_if_B( FlatSESEEnterNode a, FlatSESEEnterNode b ) {\r
+ // of A as a source for that variable: s is virtual reads\r
+ protected void remove_A_if_B( FlatSESEEnterNode a, \r
+ FlatSESEEnterNode b,\r
+ Set<TempDescriptor> liveIn,\r
+ Set<TempDescriptor> virtualLiveIn ) {\r
+\r
+ Set<VariableSourceToken> forRemoval = new HashSet<VariableSourceToken>();\r
\r
Iterator<VariableSourceToken> vstItr = get( a ).iterator();\r
while( vstItr.hasNext() ) {\r
- VariableSourceToken vst = vstItr.next();\r
-\r
- Set<VariableSourceToken> bSet = get( new SVKey( b, vst.getVarLive() ) );\r
+ VariableSourceToken vst = vstItr.next();\r
+ TempDescriptor varLive = vst.getVarLive();\r
+ Set<VariableSourceToken> bSet = get( new SVKey( b, varLive ) );\r
+ \r
if( !bSet.isEmpty() ) {\r
- remove( vst );\r
+ forRemoval.add( vst );\r
\r
// mark this variable as a virtual read as well\r
+ if( liveIn.contains( varLive ) ) {\r
+ virtualLiveIn.add( varLive );\r
+ }\r
}\r
}\r
+\r
+ vstItr = forRemoval.iterator();\r
+ while( vstItr.hasNext() ) {\r
+ VariableSourceToken vst = vstItr.next();\r
+ remove( vst );\r
+ }\r
}\r
\r
\r
// the trueSet should have all entries in s1\r
assert trueSet.containsAll( s1 );\r
\r
- // s1 should not have anything that doesn't appear in truese\r
+ // s1 should not have anything that doesn't appear in trueset\r
Set<VariableSourceToken> sInt = (Set<VariableSourceToken>) s1.clone();\r
sInt.removeAll( trueSet );\r
\r
"var2vst ="+var2vst.toString()+"\n"+\r
"sv2vst ="+sv2vst.toString();\r
}\r
+\r
+ public String toStringPretty() {\r
+ String tokHighlighter = "o";\r
+\r
+ String str = "VarSrcTokTable\n";\r
+\r
+ Set s;\r
+ Iterator itr; \r
+ Iterator<VariableSourceToken> vstItr;\r
+\r
+ str += " trueSet\n";\r
+ vstItr = trueSet.iterator(); \r
+ while( vstItr.hasNext() ) {\r
+ str += " "+tokHighlighter+" "+vstItr.next()+"\n";\r
+ }\r
+\r
+ str += " sese2vst\n";\r
+ itr = sese2vst.entrySet().iterator();\r
+ while( itr.hasNext() ) {\r
+ Map.Entry me = (Map.Entry) itr.next();\r
+ FlatSESEEnterNode sese = (FlatSESEEnterNode) me.getKey();\r
+ HashSet<VariableSourceToken> s1 = (HashSet<VariableSourceToken>) me.getValue(); \r
+ assert s1 != null;\r
+\r
+ str += " "+sese.getPrettyIdentifier()+" -> \n";\r
+\r
+ vstItr = s1.iterator();\r
+ while( vstItr.hasNext() ) {\r
+ str += " "+tokHighlighter+" "+vstItr.next()+"\n";\r
+ }\r
+ }\r
+\r
+ str += " var2vst\n";\r
+ itr = var2vst.entrySet().iterator();\r
+ while( itr.hasNext() ) {\r
+ Map.Entry me = (Map.Entry) itr.next();\r
+ TempDescriptor var = (TempDescriptor) me.getKey();\r
+ Set<VariableSourceToken> s1 = (Set<VariableSourceToken>) me.getValue();\r
+ assert s1 != null;\r
+\r
+ str += " "+var+" -> \n";\r
+\r
+ vstItr = s1.iterator();\r
+ while( vstItr.hasNext() ) {\r
+ str += " "+tokHighlighter+" "+vstItr.next()+"\n";\r
+ }\r
+ }\r
+\r
+ str += " sv2vst\n";\r
+ itr = sv2vst.entrySet().iterator();\r
+ while( itr.hasNext() ) {\r
+ Map.Entry me = (Map.Entry) itr.next();\r
+ SVKey key = (SVKey) me.getKey();\r
+ Set<VariableSourceToken> s1 = (Set<VariableSourceToken>) me.getValue();\r
+ assert s1 != null;\r
+\r
+ str += " "+key+" -> \n";\r
+\r
+ vstItr = s1.iterator();\r
+ while( vstItr.hasNext() ) {\r
+ str += " "+tokHighlighter+" "+vstItr.next()+"\n";\r
+ }\r
+ }\r
+\r
+ return str;\r
+ }\r
}\r