public class CodePlan {
private Hashtable< VariableSourceToken, Set<TempDescriptor> > stall2copySet;
- private Set<TempDescriptor> dynamicStallSet;
-
+ private Set<TempDescriptor> dynamicStallSet;
+ private Hashtable<TempDescriptor, TempDescriptor> dynAssign_lhs2rhs;
public CodePlan() {
- stall2copySet = new Hashtable< VariableSourceToken, Set<TempDescriptor> >();
- dynamicStallSet = new HashSet<TempDescriptor>();
+ stall2copySet = new Hashtable< VariableSourceToken, Set<TempDescriptor> >();
+ dynamicStallSet = new HashSet<TempDescriptor>();
+ dynAssign_lhs2rhs = new Hashtable<TempDescriptor, TempDescriptor>();
}
return dynamicStallSet;
}
+ public void addDynAssign( TempDescriptor lhs,
+ TempDescriptor rhs ) {
+ dynAssign_lhs2rhs.put( lhs, rhs );
+ }
+
+ public Hashtable<TempDescriptor, TempDescriptor> getDynAssigns() {
+ return dynAssign_lhs2rhs;
+ }
public boolean equals( Object o ) {
if( o == null ) {
boolean copySetsEq = (stall2copySet.equals( cp.stall2copySet ));
boolean dynStallSetEq = (dynamicStallSet.equals( cp.dynamicStallSet ));
+
+ boolean dynAssignEq = (dynAssign_lhs2rhs.equals( cp.dynAssign_lhs2rhs ));
- return copySetsEq && dynStallSetEq;
+ return copySetsEq && dynStallSetEq && dynAssignEq;
}
public int hashCode() {
int dynStallSetHC = dynamicStallSet.hashCode();
+ int dynAssignHC = dynAssign_lhs2rhs.hashCode();
+
int hash = 7;
hash = 31*hash + copySetsHC;
hash = 31*hash + dynStallSetHC;
+ hash = 31*hash + dynAssignHC;
return hash;
}
s += "[DYN STALLS:"+dynamicStallSet+"]";
}
+ if( !dynAssign_lhs2rhs.isEmpty() ) {
+ s += "[DYN ASSIGNS:"+dynAssign_lhs2rhs+"]";
+ }
+
return s;
}
}
pruneVariableResultsWithLiveness( fm );
}
if( state.MLPDEBUG ) {
- System.out.println( "\nVariable Results-Out\n----------------\n"+fmMain.printMethod( variableResults ) );
+ //System.out.println( "\nVariable Results-Out\n----------------\n"+fmMain.printMethod( variableResults ) );
}
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 ) );
}
}
}
+ 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();
while( inVarItr.hasNext() ) {
TempDescriptor inVar = inVarItr.next();
Integer srcType =
- vstTable.getRefVarSrcType( inVar,
+ vstTableIn.getRefVarSrcType( inVar,
fsen,
fsen.getParent() );
} 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() );
// 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 );
+ currentSESE.addDynamicVar( readtmp );
} else if( srcType.equals( VarSrcTokTable.SrcType_STATIC ) ) {
// 2) Single token/age pair: Stall for token/age pair, and copy
// 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 );
// given a table from a subsequent program point, decide
// which variables are going from a static source to a
// dynamic source and return them
- public Hashtable<TempDescriptor, VariableSourceToken> getStatic2DynamicSet( VarSrcTokTable next ) {
+ public Hashtable<TempDescriptor, VariableSourceToken>
+ getStatic2DynamicSet( VarSrcTokTable nextTable,
+ Set<TempDescriptor> nextLiveIn ) {
Hashtable<TempDescriptor, VariableSourceToken> out =
new Hashtable<TempDescriptor, VariableSourceToken>();
TempDescriptor var = (TempDescriptor) me.getKey();
HashSet<VariableSourceToken> s1 = (HashSet<VariableSourceToken>) me.getValue();
- // this is a variable with a static source if it
- // currently has one vst
- if( s1.size() == 1 ) {
- Set<VariableSourceToken> s2 = next.get( var );
+ // only worth tracking if live
+ if( nextLiveIn.contains( var ) ) {
- // and if in the next table, it is dynamic, then
- // this is a transition point, so
- if( s2.size() > 1 ) {
+ // this is a variable with a static source if it
+ // currently has one vst
+ if( s1.size() == 1 ) {
+ Set<VariableSourceToken> s2 = nextTable.get( var );
- // remember the variable and the only source
- // it had before crossing the transition
- out.put( var, s1.iterator().next() );
- }
+ // and if in the next table, it is dynamic, then
+ // this is a transition point, so
+ if( s2.size() > 1 ) {
+
+ // remember the variable and the only source
+ // it had before crossing the transition
+ out.put( var, s1.iterator().next() );
+ }
+ }
}
}
}
// declare variables for tracking dynamic sources
- Set<TempDescriptor> dynSrcVars = new HashSet<TempDescriptor>();
- dynSrcVars.addAll( fsen.getDynamicStallVarSet() );
- Iterator<FlatSESEEnterNode> childItr = fsen.getChildren().iterator();
- while( childItr.hasNext() ) {
- FlatSESEEnterNode child = childItr.next();
- dynSrcVars.addAll( child.getDynamicInVarSet() );
- }
- Iterator<TempDescriptor> dynItr = dynSrcVars.iterator();
- while( dynItr.hasNext() ) {
- TempDescriptor dynVar = dynItr.next();
- output.println(" void* "+dynVar+"_srcSESE;");
- output.println(" INTPTR "+dynVar+"_srcAddr;");
- }
-
+ Iterator<TempDescriptor> dynSrcItr = fsen.getDynamicVarSet().iterator();
+ while( dynSrcItr.hasNext() ) {
+ TempDescriptor dynSrcVar = dynSrcItr.next();
+ output.println(" void* "+dynSrcVar+"_srcSESE;");
+ output.println(" int "+dynSrcVar+"_srcOffset;");
+ }
// declare local temps for in-set primitives, and if it is
// a ready-source variable, get the value from the record
output.println(" }");
}
-
- // for each variable with a dynamic source, stall just
- // for that variable
+ // for each variable with a dynamic source, stall just for that variable
Iterator<TempDescriptor> dynItr = cp.getDynamicStallSet().iterator();
while( dynItr.hasNext() ) {
TempDescriptor dynVar = dynItr.next();
+ // only stall if the dynamic source is not yourself, denoted by src==NULL
+ // otherwise the dynamic write nodes will have the local var up-to-date
+ output.println(" {");
+ output.println(" if( "+dynVar+"_srcSESE != NULL ) {");
+ output.println(" SESEcommon* common = (SESEcommon*) "+dynVar+"_srcSESE;");
+ output.println(" psem_take( &(common->stallSem) );");
+ output.println(" "+dynVar+" = *(("+dynVar.getType()+"*) ("+
+ dynVar+"_srcSESE + "+dynVar+"_srcOffset));");
+ output.println(" }");
+ output.println(" }");
+ }
+
+ // for each assignment of a variable to rhs that has a dynamic source,
+ // copy the dynamic sources
+ Iterator dynAssignItr = cp.getDynAssigns().entrySet().iterator();
+ while( dynAssignItr.hasNext() ) {
+ Map.Entry me = (Map.Entry) dynAssignItr.next();
+ TempDescriptor lhs = (TempDescriptor) me.getKey();
+ TempDescriptor rhs = (TempDescriptor) me.getValue();
+ output.println(" "+lhs+"_srcSESE = "+rhs+"_srcSESE;");
+ output.println(" "+lhs+"_srcOffset = "+rhs+"_srcOffset;");
}
}
}
Iterator wdItr = writeDynamic.entrySet().iterator();
while( wdItr.hasNext() ) {
- Map.Entry me = (Map.Entry) wdItr.next();
- TempDescriptor var = (TempDescriptor) me.getKey();
- VariableSourceToken vst = (VariableSourceToken) me.getValue();
+ Map.Entry me = (Map.Entry) wdItr.next();
+ TempDescriptor refVar = (TempDescriptor) me.getKey();
+ VariableSourceToken vst = (VariableSourceToken) me.getValue();
SESEandAgePair instance = new SESEandAgePair( vst.getSESE(), vst.getAge() );
output.println(" {");
- output.println(" "+var+"_srcSESE = "+instance+";");
-
- output.println(" "+vst.getSESE().getSESErecordName()+"* rec = ("+
- vst.getSESE().getSESErecordName()+") "+
- instance+";");
-
- output.println(" "+var+"_srcAddr = (INTPTR) &(rec->"+vst.getAddrVar()+");");
+
+ if( fwdvn.getEnclosingSESE().equals( vst.getSESE() ) ) {
+ // if the src comes from this SESE, it's a method local variable,
+ // mark src pointer NULL to signify that the var is up-to-date
+ output.println(" "+vst.getAddrVar()+"_srcSESE = NULL;");
+ output.println(" "+refVar+" = "+vst.getAddrVar()+";");
+
+ } else {
+ // otherwise we track where it will come from
+ output.println(" "+vst.getAddrVar()+"_srcSESE = "+instance+";");
+ output.println(" "+vst.getAddrVar()+"_srcOffset = (int) &((("+
+ vst.getSESE().getSESErecordName()+"*)0)->"+vst.getAddrVar()+");");
+ }
+
output.println(" }");
}
}
protected Set<TempDescriptor> staticInVars;
protected Set<TempDescriptor> dynamicInVars;
- protected Set<TempDescriptor> dynamicStallVars;
+ protected Set<TempDescriptor> dynamicVars;
protected Hashtable<TempDescriptor, VariableSourceToken> staticInVar2src;
readyInVars = new HashSet<TempDescriptor>();
staticInVars = new HashSet<TempDescriptor>();
dynamicInVars = new HashSet<TempDescriptor>();
- dynamicStallVars = new HashSet<TempDescriptor>();
+ dynamicVars = new HashSet<TempDescriptor>();
staticInVar2src = new Hashtable<TempDescriptor, VariableSourceToken>();
}
return dynamicInVars;
}
- public void addDynamicStallVar( TempDescriptor td ) {
- dynamicStallVars.add( td );
+ public void addDynamicVar( TempDescriptor td ) {
+ dynamicVars.add( td );
}
- public Set<TempDescriptor> getDynamicStallVarSet() {
- return dynamicStallVars;
+ public Set<TempDescriptor> getDynamicVarSet() {
+ return dynamicVars;
}
public void mustTrackAtLeastAge( Integer age ) {
protected Hashtable<TempDescriptor, VariableSourceToken> var2src;
+ protected FlatSESEEnterNode enclosingSESE;
+
public FlatWriteDynamicVarNode( FlatNode t,
FlatNode h,
- Hashtable<TempDescriptor, VariableSourceToken> v2s
+ Hashtable<TempDescriptor, VariableSourceToken> v2s,
+ FlatSESEEnterNode c
) {
- tailNode = t;
- headNode = h;
- var2src = v2s;
+ tailNode = t;
+ headNode = h;
+ var2src = v2s;
+ enclosingSESE = c;
}
public void spliceIntoIR() {
return var2src;
}
+ public FlatSESEEnterNode getEnclosingSESE() {
+ return enclosingSESE;
+ }
+
public String toString() {
return "writeDynVars "+var2src.keySet();
}
}
public FlatNode clone(TempMap t) {
- return new FlatWriteDynamicVarNode( tailNode, headNode, var2src );
+ return new FlatWriteDynamicVarNode( tailNode,
+ headNode,
+ var2src,
+ enclosingSESE
+ );
}
public void rewriteUse(TempMap t) {
}
public static void main( String args[] ) {
- //int x = Integer.parseInt( args[0] );
- //int y = Integer.parseInt( args[1] );
- //System.out.println( "root: x="+x+", y="+y );
- int y = 2;
+ int x = Integer.parseInt( args[0] );
+ int y = Integer.parseInt( args[1] );
+ System.out.println( "root: x="+x+", y="+y );
- //if( x > 3 ) {
- if( true ) {
+ if( x > 3 ) {
sese fi {
y = y + 10;
}