liveout.get(exitn).addAll(liveIn);
}
// no break, sese exits should also execute default actions
-
default: {
// handle effects of statement in reverse, writes then reads
TempDescriptor [] writeTemps = fn.writesTemps();
for( int i = 0; i < writeTemps.length; ++i ) {
liveIn.remove( writeTemps[i] );
+
if (!toplevel) {
- FlatSESEExitNode exitnode=currentSESE.getFlatExit();
- Set<TempDescriptor> livetemps=liveout.get(exitnode);
- if (livetemps.contains(writeTemps[i])) {
- //write to a live out temp...
- //need to put in SESE liveout set
- currentSESE.addOutVar(writeTemps[i]);
- }
+ FlatSESEExitNode exitnode=currentSESE.getFlatExit();
+ Set<TempDescriptor> livetemps=liveout.get(exitnode);
+ if (livetemps.contains(writeTemps[i])) {
+ //write to a live out temp...
+ //need to put in SESE liveout set
+ currentSESE.addOutVar(writeTemps[i]);
+ }
}
}
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++ ) {
inUnion.merge( variableResults.get( nn ) );
}
- // check merge results before sending
- if( state.MLPDEBUG ) {
- inUnion.assertConsistency();
- }
-
VarSrcTokTable curr = variable_nodeActions( fn, inUnion, seseStack.peek() );
- // a sanity check after table operations before we proceed
- if( state.MLPDEBUG ) {
- curr.assertConsistency();
- }
-
// if a new result, schedule forward nodes for analysis
if( !curr.equals( prev ) ) {
while( itr.hasNext() ) {
VariableSourceToken vst = itr.next();
+ HashSet<TempDescriptor> ts = new HashSet<TempDescriptor>();
+ ts.add( lhs );
+
// if this is from a child, keep the source information
if( currentSESE.getChildren().contains( vst.getSESE() ) ) {
- vstTable.add( new VariableSourceToken( lhs,
+ vstTable.add( new VariableSourceToken( ts,
vst.getSESE(),
vst.getAge(),
- vst.getVarSrc()
+ vst.getAddrVar()
)
);
// otherwise, it's our or an ancestor's token so we
// can assume we have everything we need
} else {
- vstTable.add( new VariableSourceToken( lhs,
+ vstTable.add( new VariableSourceToken( ts,
currentSESE,
new Integer( 0 ),
lhs
vstTable.remove( writeTemps[0] );
- vstTable.add( new VariableSourceToken( writeTemps[0],
+ HashSet<TempDescriptor> ts = new HashSet<TempDescriptor>();
+ ts.add( writeTemps[0] );
+
+ vstTable.add( new VariableSourceToken( ts,
currentSESE,
new Integer( 0 ),
writeTemps[0]
sv2vst.put( key, \r
(HashSet<VariableSourceToken>) (s1.clone()) );\r
}\r
+\r
+ assertConsistency();\r
}\r
\r
\r
s.add( vst );\r
sese2vst.put( vst.getSESE(), s );\r
\r
- s = var2vst.get( vst.getVarLive() );\r
- if( s == null ) {\r
- s = new HashSet<VariableSourceToken>();\r
- }\r
- s.add( vst );\r
- var2vst.put( vst.getVarLive(), s );\r
+ Iterator<TempDescriptor> refVarItr = vst.getRefVars().iterator();\r
+ while( refVarItr.hasNext() ) {\r
+ TempDescriptor refVar = refVarItr.next();\r
+ s = var2vst.get( refVar );\r
+ if( s == null ) {\r
+ s = new HashSet<VariableSourceToken>();\r
+ }\r
+ s.add( vst );\r
+ var2vst.put( refVar, s );\r
\r
- SVKey key = new SVKey( vst.getSESE(), vst.getVarLive() );\r
- s = sv2vst.get( key );\r
- if( s == null ) {\r
- s = new HashSet<VariableSourceToken>();\r
+ SVKey key = new SVKey( vst.getSESE(), refVar );\r
+ s = sv2vst.get( key );\r
+ if( s == null ) {\r
+ s = new HashSet<VariableSourceToken>();\r
+ }\r
+ s.add( vst );\r
+ sv2vst.put( key, s );\r
}\r
- s.add( vst );\r
- sv2vst.put( key, s );\r
+\r
+ assertConsistency();\r
}\r
\r
public void addAll( Set<VariableSourceToken> s ) {\r
return s;\r
}\r
\r
- public Set<VariableSourceToken> get( SVKey key ) {\r
+ public Set<VariableSourceToken> get( FlatSESEEnterNode sese,\r
+ TempDescriptor refVar ) {\r
+ SVKey key = new SVKey( sese, refVar );\r
Set<VariableSourceToken> s = sv2vst.get( key );\r
if( s == null ) {\r
s = new HashSet<VariableSourceToken>();\r
return s;\r
}\r
\r
+ public Set<VariableSourceToken> get( FlatSESEEnterNode sese,\r
+ Integer age ) {\r
+ Set<VariableSourceToken> s = sese2vst.get( sese );\r
+ if( s == null ) {\r
+ s = new HashSet<VariableSourceToken>(); \r
+ sese2vst.put( sese, s );\r
+ }\r
+ Iterator<VariableSourceToken> sItr = s.iterator();\r
+ while( sItr.hasNext() ) {\r
+ VariableSourceToken vst = sItr.next();\r
+ if( !vst.getAge().equals( age ) ) {\r
+ s.remove( vst );\r
+ }\r
+ }\r
+ return s;\r
+ }\r
+\r
\r
public void merge( VarSrcTokTable tableIn ) {\r
\r
this.sv2vst.put( key, s2 );\r
} \r
}\r
+\r
+ assertConsistency();\r
}\r
\r
\r
s = get( vst.getSESE() );\r
if( s != null ) { s.remove( vst ); }\r
\r
- s = get( vst.getVarLive() );\r
- if( s != null ) { s.remove( vst ); }\r
+ Iterator<TempDescriptor> refVarItr = vst.getRefVars().iterator();\r
+ while( refVarItr.hasNext() ) {\r
+ TempDescriptor refVar = refVarItr.next();\r
\r
- s = get( new SVKey( vst.getSESE(), vst.getVarLive() ) );\r
- if( s != null ) { s.remove( vst ); }\r
+ s = get( refVar );\r
+ if( s != null ) { s.remove( vst ); }\r
+ \r
+ s = get( vst.getSESE(), refVar );\r
+ if( s != null ) { s.remove( vst ); }\r
+ }\r
+\r
+ assertConsistency();\r
}\r
\r
public void remove( FlatSESEEnterNode sese ) {\r
if( s == null ) {\r
return;\r
}\r
- \r
- trueSet.removeAll( s );\r
- sese2vst.remove( sese );\r
\r
Iterator<VariableSourceToken> itr = s.iterator();\r
while( itr.hasNext() ) {\r
VariableSourceToken vst = itr.next();\r
remove( vst );\r
}\r
+\r
+ sese2vst.remove( sese );\r
+\r
+ assertConsistency();\r
}\r
\r
- public void remove( TempDescriptor var ) {\r
- Set<VariableSourceToken> s = var2vst.get( var );\r
+ public void remove( TempDescriptor refVar ) {\r
+ Set<VariableSourceToken> s = var2vst.get( refVar );\r
if( s == null ) {\r
return;\r
}\r
\r
- trueSet.removeAll( s ); \r
- var2vst.remove( var );\r
+ Set<VariableSourceToken> forRemoval = new HashSet<VariableSourceToken>();\r
\r
+ // iterate over tokens that this temp can reference, make a set\r
+ // of tokens that need this temp stripped out of them\r
Iterator<VariableSourceToken> itr = s.iterator();\r
while( itr.hasNext() ) {\r
+ VariableSourceToken vst = itr.next();\r
+ Set<TempDescriptor> refVars = vst.getRefVars();\r
+ assert refVars.contains( refVar );\r
+ forRemoval.add( vst );\r
+ }\r
+\r
+ itr = forRemoval.iterator();\r
+ while( itr.hasNext() ) {\r
+ // here's a token marked for removal, take it out as it is\r
+ // in this state\r
VariableSourceToken vst = itr.next();\r
remove( vst );\r
+\r
+ // if there are other references to the token, alter the\r
+ // token and then readd it to this table, because it has\r
+ // a new hash value now\r
+ Set<TempDescriptor> refVars = vst.getRefVars();\r
+ refVars.remove( refVar );\r
+ if( refVars.size() > 0 ) {\r
+ add( vst );\r
+ }\r
}\r
+\r
+ //var2vst.remove( var );\r
+\r
+ assertConsistency();\r
}\r
\r
public void remove( FlatSESEEnterNode sese,\r
return;\r
}\r
\r
- trueSet.removeAll( s );\r
- sv2vst.remove( key );\r
-\r
Iterator<VariableSourceToken> itr = s.iterator();\r
while( itr.hasNext() ) {\r
VariableSourceToken vst = itr.next();\r
remove( vst );\r
}\r
+\r
+ sv2vst.remove( key );\r
+\r
+ assertConsistency();\r
}\r
\r
\r
\r
out.remove( vst );\r
\r
- out.add( new VariableSourceToken( vst.getVarLive(), \r
+ out.add( new VariableSourceToken( vst.getRefVars(), \r
curr, \r
newAge,\r
- vst.getVarSrc() \r
+ vst.getAddrVar()\r
)\r
);\r
} \r
}\r
\r
+ out.assertConsistency();\r
return out;\r
}\r
\r
\r
remove( vst );\r
\r
- add( new VariableSourceToken( vst.getVarLive(),\r
+ add( new VariableSourceToken( vst.getRefVars(),\r
curr,\r
new Integer( 0 ),\r
- vst.getVarLive() ) );\r
+ vst.getAddrVar()\r
+ )\r
+ );\r
}\r
}\r
+\r
+ assertConsistency();\r
} \r
\r
\r
}\r
}\r
\r
+ assertConsistency();\r
return virtualLiveIn;\r
}\r
\r
\r
Iterator<VariableSourceToken> vstItr = get( a ).iterator();\r
while( vstItr.hasNext() ) {\r
- VariableSourceToken vst = vstItr.next();\r
- TempDescriptor varLive = vst.getVarLive();\r
- Set<VariableSourceToken> bSet = get( new SVKey( b, varLive ) );\r
+ VariableSourceToken vst = vstItr.next();\r
+ Iterator<TempDescriptor> refVarItr = vst.getRefVars().iterator();\r
+ while( refVarItr.hasNext() ) {\r
+ TempDescriptor refVar = refVarItr.next();\r
+ Set<VariableSourceToken> bSet = get( b, refVar );\r
\r
- if( !bSet.isEmpty() ) {\r
- forRemoval.add( vst );\r
-\r
- // mark this variable as a virtual read as well\r
- //if( liveInCurrentSESE.contains( varLive ) ) { ???????????\r
- virtualLiveIn.add( varLive );\r
- //}\r
+ if( !bSet.isEmpty() ) {\r
+ forRemoval.add( vst );\r
+\r
+ // mark this variable as a virtual read as well\r
+ //if( liveInCurrentSESE.contains( varLive ) ) { ???????????\r
+ virtualLiveIn.add( refVar );\r
+ //}\r
+ }\r
}\r
}\r
\r
- /*\r
- System.out.println( "remove "+a.getPrettyIdentifier()+" if "+b.getPrettyIdentifier() );\r
- System.out.println( "THIS "+toStringPretty() );\r
- System.out.println( "for removal="+forRemoval );\r
- */\r
-\r
vstItr = forRemoval.iterator();\r
while( vstItr.hasNext() ) {\r
VariableSourceToken vst = vstItr.next();\r
Set s;\r
\r
Set<VariableSourceToken> trueSetByAlts = new HashSet<VariableSourceToken>();\r
-\r
itr = sese2vst.entrySet().iterator();\r
while( itr.hasNext() ) {\r
Map.Entry me = (Map.Entry) itr.next();\r
// add s1 to a running union--at the end check if trueSet has extra\r
trueSetByAlts.addAll( s1 );\r
}\r
+ // make sure trueSet isn't too big\r
+ assert trueSetByAlts.containsAll( trueSet );\r
+\r
+\r
+ trueSetByAlts = new HashSet<VariableSourceToken>();\r
+ itr = var2vst.entrySet().iterator();\r
+ while( itr.hasNext() ) {\r
+ Map.Entry me = (Map.Entry) itr.next();\r
+ TempDescriptor var = (TempDescriptor) me.getKey();\r
+ HashSet<VariableSourceToken> s1 = (HashSet<VariableSourceToken>) me.getValue(); \r
+ assert s1 != null;\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 trueset\r
+ Set<VariableSourceToken> sInt = (Set<VariableSourceToken>) s1.clone();\r
+ sInt.removeAll( trueSet );\r
+\r
+ assert sInt.isEmpty();\r
\r
+ // add s1 to a running union--at the end check if trueSet has extra\r
+ trueSetByAlts.addAll( s1 );\r
+ }\r
+ // make sure trueSet isn't too big\r
+ assert trueSetByAlts.containsAll( trueSet );\r
+\r
+\r
+ trueSetByAlts = new HashSet<VariableSourceToken>();\r
+ itr = sv2vst.entrySet().iterator();\r
+ while( itr.hasNext() ) {\r
+ Map.Entry me = (Map.Entry) itr.next();\r
+ SVKey key = (SVKey) me.getKey();\r
+ HashSet<VariableSourceToken> s1 = (HashSet<VariableSourceToken>) me.getValue(); \r
+ assert s1 != null;\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 trueset\r
+ Set<VariableSourceToken> sInt = (Set<VariableSourceToken>) s1.clone();\r
+ sInt.removeAll( trueSet );\r
+\r
+ assert sInt.isEmpty();\r
+\r
+ // add s1 to a running union--at the end check if trueSet has extra\r
+ trueSetByAlts.addAll( s1 );\r
+ }\r
// make sure trueSet isn't too big\r
assert trueSetByAlts.containsAll( trueSet );\r
}\r
public class VariableSourceToken {
- private TempDescriptor varLive;
- private FlatSESEEnterNode seseSrc;
- private Integer seseAge;
- private TempDescriptor varSrc;
+ private Set<TempDescriptor> refVars;
+ private FlatSESEEnterNode sese;
+ private Integer seseAge;
+ private TempDescriptor addrVar;
- public VariableSourceToken( TempDescriptor varLive,
- FlatSESEEnterNode seseSrc,
- Integer seseAge,
- TempDescriptor varSrc
+ public VariableSourceToken( Set<TempDescriptor> refVars,
+ FlatSESEEnterNode sese,
+ Integer seseAge,
+ TempDescriptor addrVar
) {
- this.varLive = varLive;
- this.seseSrc = seseSrc;
+ this.refVars = refVars;
+ this.sese = sese;
this.seseAge = seseAge;
- this.varSrc = varSrc;
+ this.addrVar = addrVar;
}
- public TempDescriptor getVarLive() {
- return varLive;
+ public Set<TempDescriptor> getRefVars() {
+ return refVars;
}
public FlatSESEEnterNode getSESE() {
- return seseSrc;
+ return sese;
}
public Integer getAge() {
return seseAge;
}
- public TempDescriptor getVarSrc() {
- return varSrc;
+ public TempDescriptor getAddrVar() {
+ return addrVar;
}
public boolean equals( Object o ) {
VariableSourceToken vst = (VariableSourceToken) o;
- return seseSrc.equals( vst.seseSrc ) &&
- varSrc.equals( vst.varSrc ) &&
- seseAge.equals( vst.seseAge ) &&
- varLive.equals( vst.varLive );
+ // the reference vars have no bearing on equality
+ return sese.equals( vst.sese ) &&
+ addrVar.equals( vst.addrVar ) &&
+ seseAge.equals( vst.seseAge );
}
public int hashCode() {
- return (seseSrc.hashCode() << 3) + (varSrc.hashCode() << 4) * (varLive.hashCode() << 2) ^ seseAge.intValue();
+ // the reference vars have no bearing on hashCode
+ return (sese.hashCode() << 3) * (addrVar.hashCode() << 4) ^ seseAge.intValue();
}
public String toString() {
- return varLive+" from "+varSrc+" in "+seseSrc.getPrettyIdentifier()+"("+seseAge+")";
+ return refVars+" ref "+addrVar+"@"+sese.getPrettyIdentifier()+"("+seseAge+")";
}
}