notAvailableForward( fm );
}
if( state.MLPDEBUG ) {
- System.out.println( "\nNot Available Results-Out\n---------------------\n"+fmMain.printMethod( notAvailableResults ) );
+ //System.out.println( "\nNot Available Results-Out\n---------------------\n"+fmMain.printMethod( notAvailableResults ) );
}
computeStallsForward( fm );
}
if( state.MLPDEBUG ) {
- System.out.println( "\nCode Plans\n----------\n"+fmMain.printMethod( codePlans ) );
+ //System.out.println( "\nCode Plans\n----------\n"+fmMain.printMethod( codePlans ) );
}
-
// splice new IR nodes into graph after all
// analysis passes are complete
Iterator spliceItr = wdvNodesToSpliceIn.entrySet().iterator();
fwdvn.spliceIntoIR();
}
+ // detailed per-SESE information
+ if( state.MLPDEBUG ) {
+ System.out.println( "\nSESE info\n-------------\n" ); printSESEInfo();
+ }
double timeEndAnalysis = (double) System.nanoTime();
double dt = (timeEndAnalysis - timeStartAnalysis)/(Math.pow( 10.0, 9.0 ) );
}
}
+ private void printSESEInfo() {
+ printSESEInfoTree( rootSESE );
+ System.out.println( "" );
+ }
+
+ private void printSESEInfoTree( FlatSESEEnterNode fsen ) {
+
+ System.out.println( "SESE "+fsen.getPrettyIdentifier()+" {" );
+
+ System.out.println( " in-set: "+fsen.getInVarSet() );
+ Iterator<TempDescriptor> tItr = fsen.getInVarSet().iterator();
+ while( tItr.hasNext() ) {
+ TempDescriptor inVar = tItr.next();
+ if( fsen.getReadyInVarSet().contains( inVar ) ) {
+ System.out.println( " (ready) "+inVar );
+ }
+ if( fsen.getStaticInVarSet().contains( inVar ) ) {
+ System.out.println( " (static) "+inVar );
+ }
+ if( fsen.getDynamicInVarSet().contains( inVar ) ) {
+ System.out.println( " (dynamic)"+inVar );
+ }
+ }
+
+ System.out.println( " out-set: "+fsen.getOutVarSet() );
+
+ /*
+ System.out.println( " static names to track:" );
+ tItr = fsen.getOutVarSet().iterator();
+ while( tItr.hasNext() ) {
+ System.out.println( " "+tItr.next() );
+ }
+ */
+
+ System.out.println( "}" );
+
+ Iterator<FlatSESEEnterNode> childItr = fsen.getChildren().iterator();
+ while( childItr.hasNext() ) {
+ FlatSESEEnterNode fsenChild = childItr.next();
+ printSESEInfoTree( fsenChild );
+ }
+ }
+
private void variableAnalysisForward( FlatMethod fm ) {
case FKind.FlatSESEEnterNode: {
FlatSESEEnterNode fsen = (FlatSESEEnterNode) fn;
assert fsen.equals( currentSESE );
+
vstTable.age( currentSESE );
vstTable.assertConsistency();
+
+ vstTable.ownInSet( currentSESE );
+ vstTable.assertConsistency();
} break;
case FKind.FlatSESEExitNode: {
TempDescriptor rTemp = readTemps[i];
notAvailSet.remove( rTemp );
- // if this variable has exactly one source, mark everything
- // else from that source as available as well
+ // if this variable has exactly one source, potentially
+ // get other things from this source as well
VarSrcTokTable vstTable = variableResults.get( fn );
Integer srcType =
Iterator<VariableSourceToken> availItr = vstTable.get( vst.getSESE(),
vst.getAge()
).iterator();
+
+ // look through things that are also available from same source
while( availItr.hasNext() ) {
VariableSourceToken vstAlsoAvail = availItr.next();
- notAvailSet.removeAll( vstAlsoAvail.getRefVars() );
+
+ Iterator<TempDescriptor> refVarItr = vstAlsoAvail.getRefVars().iterator();
+ while( refVarItr.hasNext() ) {
+ TempDescriptor refVarAlso = refVarItr.next();
+
+ // if a variable is available from the same source, AND it ALSO
+ // only comes from one statically known source, mark it available
+ Integer srcTypeAlso =
+ vstTable.getRefVarSrcType( refVarAlso,
+ currentSESE,
+ currentSESE.getParent() );
+ if( srcTypeAlso.equals( VarSrcTokTable.SrcType_STATIC ) ) {
+ notAvailSet.remove( refVarAlso );
+ }
+ }
}
}
}
}
}
+ Set<TempDescriptor> dotSTlive = livenessRootView.get( fn );
+
if( !seseStack.empty() ) {
- computeStalls_nodeActions( fn, dotSTtable, dotSTnotAvailSet, seseStack.peek() );
+ computeStalls_nodeActions( fn,
+ dotSTlive,
+ dotSTtable,
+ dotSTnotAvailSet,
+ seseStack.peek()
+ );
}
for( int i = 0; i < fn.numNext(); i++ ) {
}
private void computeStalls_nodeActions( FlatNode fn,
- VarSrcTokTable vstTable,
- Set<TempDescriptor> notAvailSet,
+ Set<TempDescriptor> liveSetIn,
+ VarSrcTokTable vstTableIn,
+ Set<TempDescriptor> notAvailSetIn,
FlatSESEEnterNode currentSESE ) {
- CodePlan plan = new CodePlan();
+ CodePlan plan = new CodePlan( currentSESE);
switch( fn.kind() ) {
while( inVarItr.hasNext() ) {
TempDescriptor inVar = inVarItr.next();
Integer srcType =
- vstTable.getRefVarSrcType( inVar,
- fsen,
- fsen.getParent() );
+ vstTableIn.getRefVarSrcType( inVar,
+ fsen,
+ fsen.getParent() );
+ // the current SESE needs a local space to track the dynamic
+ // variable and the child needs space in its SESE record
if( srcType.equals( VarSrcTokTable.SrcType_DYNAMIC ) ) {
fsen.addDynamicInVar( inVar );
+ fsen.getParent().addDynamicVar( inVar );
} else if( srcType.equals( VarSrcTokTable.SrcType_STATIC ) ) {
fsen.addStaticInVar( inVar );
- VariableSourceToken vst = vstTable.get( inVar ).iterator().next();
+ VariableSourceToken vst = vstTableIn.get( inVar ).iterator().next();
fsen.putStaticInVar2src( inVar, vst );
fsen.addStaticInVarSrc( new SESEandAgePair( vst.getSESE(),
vst.getAge()
FlatOpNode fon = (FlatOpNode) fn;
if( fon.getOp().getOp() == Operation.ASSIGN ) {
+ TempDescriptor lhs = fon.getDest();
+ TempDescriptor rhs = fon.getLeft();
+
// if this is an op node, don't stall, copy
// source and delay until we need to use value
+ // but check the source type of rhs variable
+ // and if dynamic, lhs becomes dynamic, too,
+ // and we need to keep dynamic sources during
+ Integer srcType
+ = vstTableIn.getRefVarSrcType( rhs,
+ currentSESE,
+ currentSESE.getParent() );
+
+ if( srcType.equals( VarSrcTokTable.SrcType_DYNAMIC ) ) {
+ plan.addDynAssign( lhs, rhs );
+ currentSESE.addDynamicVar( lhs );
+ currentSESE.addDynamicVar( rhs );
+ }
+
// only break if this is an ASSIGN op node,
// otherwise fall through to default case
break;
default: {
// a node with no live set has nothing to stall for
- Set<TempDescriptor> liveSet = livenessRootView.get( fn );
- if( liveSet == null ) {
+ if( liveSetIn == null ) {
break;
}
// ignore temps that are definitely available
// when considering to stall on it
- if( !notAvailSet.contains( readtmp ) ) {
+ if( !notAvailSetIn.contains( readtmp ) ) {
continue;
}
// check the source type of this variable
Integer srcType
- = vstTable.getRefVarSrcType( readtmp,
+ = vstTableIn.getRefVarSrcType( readtmp,
currentSESE,
currentSESE.getParent() );
-
- System.out.println( "considering stall on "+readtmp+" for "+currentSESE );
-
if( srcType.equals( VarSrcTokTable.SrcType_DYNAMIC ) ) {
// 1) It is not clear statically where this variable will
// come from statically, so dynamically we must keep track
// along various control paths, and therefore when we stall,
// just stall for the exact thing we need and move on
plan.addDynamicStall( readtmp );
- currentSESE.addDynamicStallVar( readtmp );
- System.out.println( "ADDING "+readtmp+" TO "+currentSESE+" DYNSTALLSET" );
-
+ currentSESE.addDynamicVar( readtmp );
+
} else if( srcType.equals( VarSrcTokTable.SrcType_STATIC ) ) {
// 2) Single token/age pair: Stall for token/age pair, and copy
// all live variables with same token/age pair at the same
// time. This is the same stuff that the notavaialable analysis
// marks as now available.
- VariableSourceToken vst = vstTable.get( readtmp ).iterator().next();
+ VariableSourceToken vst = vstTableIn.get( readtmp ).iterator().next();
Iterator<VariableSourceToken> availItr =
- vstTable.get( vst.getSESE(), vst.getAge() ).iterator();
+ vstTableIn.get( vst.getSESE(), vst.getAge() ).iterator();
while( availItr.hasNext() ) {
VariableSourceToken vstAlsoAvail = availItr.next();
Iterator<TempDescriptor> refVarItr = vstAlsoAvail.getRefVars().iterator();
while( refVarItr.hasNext() ) {
TempDescriptor refVar = refVarItr.next();
- if( liveSet.contains( refVar ) ) {
+ if( liveSetIn.contains( refVar ) ) {
copySet.add( refVar );
}
}
}
} break;
-
+
} // end switch
// identify sese-age pairs that are statically useful
// and should have an associated SESE variable in code
- Set<VariableSourceToken> staticSet = vstTable.getStaticSet();
+ Set<VariableSourceToken> staticSet = vstTableIn.getStaticSet();
Iterator<VariableSourceToken> vstItr = staticSet.iterator();
while( vstItr.hasNext() ) {
VariableSourceToken vst = vstItr.next();
codePlans.put( fn, plan );
- // if any variables at this node have a static source (exactly one vst)
- // but go to a dynamic source at a next node, create a new IR graph
+ // if any variables at this-node-*dot* have a static source (exactly one vst)
+ // but go to a dynamic source at next-node-*dot*, create a new IR graph
// node on that edge to track the sources dynamically
+ VarSrcTokTable thisVstTable = variableResults.get( fn );
for( int i = 0; i < fn.numNext(); i++ ) {
- FlatNode nn = fn.getNext( i );
- VarSrcTokTable nextVstTable = variableResults.get( nn );
+ FlatNode nn = fn.getNext( i );
+ VarSrcTokTable nextVstTable = variableResults.get( nn );
+ Set<TempDescriptor> nextLiveIn = livenessRootView.get( nn );
// the table can be null if it is one of the few IR nodes
// completely outside of the root SESE scope
- if( nextVstTable != null ) {
+ if( nextVstTable != null && nextLiveIn != null ) {
Hashtable<TempDescriptor, VariableSourceToken> static2dynamicSet =
- vstTable.getStatic2DynamicSet( nextVstTable );
+ thisVstTable.getStatic2DynamicSet( nextVstTable, nextLiveIn );
if( !static2dynamicSet.isEmpty() ) {
FlatWriteDynamicVarNode fwdvn = wdvNodesToSpliceIn.get( fe );
if( fwdvn == null ) {
- fwdvn = new FlatWriteDynamicVarNode( fn, nn, static2dynamicSet );
+ fwdvn = new FlatWriteDynamicVarNode( fn,
+ nn,
+ static2dynamicSet,
+ currentSESE
+ );
wdvNodesToSpliceIn.put( fe, fwdvn );
} else {
fwdvn.addMoreVar2Src( static2dynamicSet );