private Set<FlatSESEEnterNode> seseRoots;
private Hashtable< FlatNode, Stack<FlatSESEEnterNode> > seseStacks;
-
- private Hashtable< FlatNode, Set<VariableSourceToken> > pointResults;
+ private Hashtable< FlatNode, VarSrcTokTable > pointResults;
public MLPAnalysis( State state,
// initialize analysis data structures
seseRoots = new HashSet<FlatSESEEnterNode>();
seseStacks = new Hashtable< FlatNode, Stack<FlatSESEEnterNode> >();
- pointResults = new Hashtable< FlatNode, Set<VariableSourceToken> >();
+ pointResults = new Hashtable< FlatNode, VarSrcTokTable >();
// run analysis on each method that is actually called
analyzeFlatNodeForward( fn, seseStack );
// initialize for backward computation in next step
- pointResults.put( fn, new HashSet<VariableSourceToken>() );
+ pointResults.put( fn, new VarSrcTokTable() );
for( int i = 0; i < fn.numNext(); i++ ) {
FlatNode nn = fn.getNext( i );
FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next();
flatNodesToVisit.remove( fn );
- Set<VariableSourceToken> prev = pointResults.get( fn );
+ VarSrcTokTable prev = pointResults.get( fn );
// merge sets from control flow joins
- Set<VariableSourceToken> merge = new HashSet<VariableSourceToken>();
+ VarSrcTokTable inUnion = new VarSrcTokTable();
for( int i = 0; i < fn.numNext(); i++ ) {
- FlatNode nn = fn.getNext( i );
- merge = mergeVSTsets( merge, pointResults.get( nn ) );
+ FlatNode nn = fn.getNext( i );
+ inUnion.merge( pointResults.get( nn ) );
}
- Set<VariableSourceToken> curr = analyzeFlatNodeBackward( fn, merge, fsen );
+ VarSrcTokTable curr = analyzeFlatNodeBackward( fn, inUnion, fsen );
// if a new result, schedule backward nodes for analysis
if( !prev.equals( curr ) ) {
}
- private Set<VariableSourceToken> analyzeFlatNodeBackward( FlatNode fn,
- Set<VariableSourceToken> vstSet,
- FlatSESEEnterNode currentSESE ) {
+ private VarSrcTokTable analyzeFlatNodeBackward( FlatNode fn,
+ VarSrcTokTable vstTable,
+ FlatSESEEnterNode currentSESE ) {
switch( fn.kind() ) {
case FKind.FlatSESEEnterNode: {
// handle effects of statement in reverse, writes then reads
TempDescriptor [] writeTemps = fn.writesTemps();
for( int i = 0; i < writeTemps.length; ++i ) {
- vstSet = killTemp( vstSet, writeTemps[i] );
+ vstTable.remove( writeTemps[i] );
}
TempDescriptor [] readTemps = fn.readsTemps();
for( int i = 0; i < readTemps.length; ++i ) {
- Set<VariableSourceToken> vstNew = new HashSet<VariableSourceToken>();
- vstNew.add( new VariableSourceToken( currentSESE,
- readTemps[i],
- new Integer( 0 ) ) );
- vstSet = mergeVSTsets( vstSet, vstNew );
+ vstTable.add( new VariableSourceToken( currentSESE,
+ readTemps[i],
+ new Integer( 0 ) ) );
}
} break;
} // end switch
- return vstSet;
- }
-
-
- private Set<VariableSourceToken> killTemp( Set<VariableSourceToken> s,
- TempDescriptor t ) {
- Set<VariableSourceToken> out = new HashSet<VariableSourceToken>();
-
- Iterator<VariableSourceToken> vstitr = s.iterator();
- while( vstitr.hasNext() ) {
- VariableSourceToken vst = vstitr.next();
-
- if( !vst.getVar().equals( t ) ) {
- out.add( vst );
- }
- }
-
- return out;
- }
-
-
- private Set<VariableSourceToken> mergeVSTsets( Set<VariableSourceToken> s1,
- Set<VariableSourceToken> s2 ) {
-
- Set<VariableSourceToken> out = new HashSet<VariableSourceToken>();
-
- Iterator<VariableSourceToken> vst1itr = s1.iterator();
- while( vst1itr.hasNext() ) {
- VariableSourceToken vst1 = vst1itr.next();
-
- int changeAge = -1;
-
- Iterator<VariableSourceToken> vst2itr = s2.iterator();
- while( vst2itr.hasNext() ) {
- VariableSourceToken vst2 = vst2itr.next();
-
- if( vst1.getSESE().equals( vst2.getSESE() ) &&
- vst1.getVar() .equals( vst2.getVar() ) ) {
- changeAge = vst1.getAge();
- int a = vst2.getAge();
- if( a < changeAge ) {
- changeAge = a;
- }
- break;
- }
- }
-
- if( changeAge < 0 ) {
- out.add( vst1 );
- } else {
- out.add( new VariableSourceToken( vst1.getSESE(),
- vst1.getVar(),
- new Integer( changeAge ) ) );
- }
- }
-
-
- Iterator<VariableSourceToken> vst2itr = s2.iterator();
- while( vst2itr.hasNext() ) {
- VariableSourceToken vst2 = vst2itr.next();
-
- boolean matchSESEandVar = false;
-
- vst1itr = s1.iterator();
- while( vst1itr.hasNext() ) {
- VariableSourceToken vst1 = vst1itr.next();
-
- if( vst1.getSESE().equals( vst2.getSESE() ) &&
- vst1.getVar() .equals( vst2.getVar() ) ) {
- matchSESEandVar = true;
- break;
- }
- }
-
- if( !matchSESEandVar ) {
- out.add( vst2 );
- }
- }
-
-
- return out;
+ return vstTable;
}
}
-
-
public void merge( VarSrcTokTable table ) {
trueSet.addAll( table.trueSet );
- Iterator i;
+ Iterator itr;
Set s;
- itr = sese2vst.getEntrySet().iterator();
+ itr = sese2vst.entrySet().iterator();
while( itr.hasNext() ) {
Map.Entry me = (Map.Entry) itr.next();
FlatSESEEnterNode sese = (FlatSESEEnterNode) me.getKey();
s1.addAll( s2 );
}
}
- s = table.sese2vst.getEntrySet();
- s.retainAll( sese2vst.getEntrySet() );
+ s = table.sese2vst.entrySet();
+ s.retainAll( sese2vst.entrySet() );
sese2vst.putAll( table.sese2vst );
- itr = var2vst.getEntrySet().iterator();
+ itr = var2vst.entrySet().iterator();
while( itr.hasNext() ) {
Map.Entry me = (Map.Entry) itr.next();
TempDescriptor var = (TempDescriptor) me.getKey();
s1.addAll( s2 );
}
}
- s = table.var2vst.getEntrySet();
- s.retainAll( var2vst.getEntrySet() );
+ s = table.var2vst.entrySet();
+ s.retainAll( var2vst.entrySet() );
var2vst.putAll( table.var2vst );
- itr = sv2vst.getEntrySet().iterator();
+ itr = sv2vst.entrySet().iterator();
while( itr.hasNext() ) {
Map.Entry me = (Map.Entry) itr.next();
SVKey key = (SVKey) me.getKey();
s1.addAll( s2 );
}
}
- s = table.sv2vst.getEntrySet();
- s.retainAll( sv2vst.getEntrySet() );
+ s = table.sv2vst.entrySet();
+ s.retainAll( sv2vst.entrySet() );
sv2vst.putAll( table.sv2vst );
}
}
trueSet.removeAll( s );
- sese2vst.remove( sese );
- var2vst .remove( var );
sv2vst .remove( key );
}
+ public void remove( VariableSourceToken vst ) {
+ trueSet.remove( vst );
+ }
+
public boolean equals( Object o ) {
if( o == null ) {
return false;
return trueSet.hashCode();
}
+ public Iterator<VariableSourceToken> iterator() {
+ return trueSet.iterator();
+ }
+
public String toString() {
return trueSet.toString();
}