-package Analysis.MLP;
-
-import IR.*;
-import IR.Flat.*;
-import java.util.*;
-import java.io.*;
-
-public class VarSrcTokTable {
-
- // the true set represents the set of (sese, variable, age)
- // triples that are truly in the table
- private HashSet<VariableSourceToken> trueSet;
-
- // these hashtables provide an efficient retreival from the
- // true set. Note that a particular triple from the quick
- // look up must be checked against the true set--remove ops
- // can cause the hashtables to be inconsistent to each other
- private Hashtable< TempDescriptor, Set<VariableSourceToken> > var2vst;
- private Hashtable< FlatSESEEnterNode, Set<VariableSourceToken> > sese2vst;
- private Hashtable< SVKey, Set<VariableSourceToken> > sv2vst;
-
- // maximum age from aging operation
- private Integer MAX_AGE = new Integer( 2 );
-
-
- public VarSrcTokTable() {
- trueSet = new HashSet<VariableSourceToken>();
-
- sese2vst = new Hashtable< FlatSESEEnterNode, Set<VariableSourceToken> >();
- var2vst = new Hashtable< TempDescriptor, Set<VariableSourceToken> >();
- sv2vst = new Hashtable< SVKey, Set<VariableSourceToken> >();
- }
-
-
- public void add( VariableSourceToken vst ) {
- trueSet.add( vst );
-
- Set<VariableSourceToken> s;
-
- s = sese2vst.get( vst.getSESE() );
- if( s == null ) {
- s = new HashSet<VariableSourceToken>();
- }
- s.add( vst );
- sese2vst.put( vst.getSESE(), s );
-
- s = var2vst.get( vst.getVarLive() );
- if( s == null ) {
- s = new HashSet<VariableSourceToken>();
- }
- s.add( vst );
- var2vst.put( vst.getVarLive(), s );
-
- SVKey key = new SVKey( vst.getSESE(), vst.getVarLive() );
- s = sv2vst.get( key );
- if( s == null ) {
- s = new HashSet<VariableSourceToken>();
- }
- s.add( vst );
- sv2vst.put( key, s );
- }
-
- public void addAll( Set<VariableSourceToken> s ) {
- Iterator<VariableSourceToken> itr = s.iterator();
- while( itr.hasNext() ) {
- add( itr.next() );
- }
- }
-
-
- public Set<VariableSourceToken> get() {
- return trueSet;
- }
-
- public Set<VariableSourceToken> get( FlatSESEEnterNode sese ) {
- Set<VariableSourceToken> s = sese2vst.get( sese );
- if( s == null ) {
- s = new HashSet<VariableSourceToken>();
- sese2vst.put( sese, s );
- }
- s.retainAll( trueSet );
- return s;
- }
-
- public Set<VariableSourceToken> get( TempDescriptor var ) {
- Set<VariableSourceToken> s = var2vst.get( var );
- if( s == null ) {
- s = new HashSet<VariableSourceToken>();
- var2vst.put( var, s );
- }
- s.retainAll( trueSet );
- return s;
- }
-
- public Set<VariableSourceToken> get( SVKey key ) {
- Set<VariableSourceToken> s = sv2vst.get( key );
- if( s == null ) {
- s = new HashSet<VariableSourceToken>();
- sv2vst.put( key, s );
- }
- s.retainAll( trueSet );
- return s;
- }
-
-
- public void merge( VarSrcTokTable table ) {
-
- if( table == null ) {
- return;
- }
-
- trueSet.addAll( table.trueSet );
-
- Iterator itr;
- Set s;
-
- itr = sese2vst.entrySet().iterator();
- while( itr.hasNext() ) {
- Map.Entry me = (Map.Entry) itr.next();
- FlatSESEEnterNode sese = (FlatSESEEnterNode) me.getKey();
- Set<VariableSourceToken> s1 = (Set<VariableSourceToken>) me.getValue();
- Set<VariableSourceToken> s2 = table.sese2vst.get( sese );
-
- assert s1 != null;
-
- if( s2 != null ) {
- s1.addAll( s2 );
- }
- }
- s = table.sese2vst.entrySet();
- s.removeAll( sese2vst.entrySet() );
- sese2vst.putAll( table.sese2vst );
-
- itr = var2vst.entrySet().iterator();
- while( itr.hasNext() ) {
- Map.Entry me = (Map.Entry) itr.next();
- TempDescriptor var = (TempDescriptor) me.getKey();
- Set<VariableSourceToken> s1 = (Set<VariableSourceToken>) me.getValue();
- Set<VariableSourceToken> s2 = table.var2vst.get( var );
-
- assert s1 != null;
-
- if( s2 != null ) {
- s1.addAll( s2 );
- }
- }
- s = table.var2vst.entrySet();
- s.removeAll( var2vst.entrySet() );
- var2vst.putAll( table.var2vst );
-
- itr = sv2vst.entrySet().iterator();
- while( itr.hasNext() ) {
- Map.Entry me = (Map.Entry) itr.next();
- SVKey key = (SVKey) me.getKey();
- Set<VariableSourceToken> s1 = (Set<VariableSourceToken>) me.getValue();
- Set<VariableSourceToken> s2 = table.sv2vst.get( key );
-
- assert s1 != null;
-
- if( s2 != null ) {
- s1.addAll( s2 );
- }
- }
- s = table.sv2vst.entrySet();
- s.removeAll( sv2vst.entrySet() );
- sv2vst.putAll( table.sv2vst );
- }
-
-
- public void remove( FlatSESEEnterNode sese ) {
- Set<VariableSourceToken> s = sese2vst.get( sese );
- if( s == null ) {
- return;
- }
-
- trueSet.removeAll( s );
- sese2vst.remove( sese );
- }
-
- public void remove( TempDescriptor var ) {
- Set<VariableSourceToken> s = var2vst.get( var );
- if( s == null ) {
- return;
- }
-
- trueSet.removeAll( s );
- var2vst.remove( var );
- }
-
- public void remove( FlatSESEEnterNode sese,
- TempDescriptor var ) {
-
- SVKey key = new SVKey( sese, var );
- Set<VariableSourceToken> s = sv2vst.get( key );
- if( s == null ) {
- return;
- }
-
- trueSet.removeAll( s );
- sv2vst.remove( key );
- }
-
- public void remove( VariableSourceToken vst ) {
- trueSet.remove( vst );
- }
-
-
- // return a new table based on this one and
- // age tokens with respect to SESE curr, where
- // any child becomes curr with age 0, and any
- // curr tokens increase age by 1
- public VarSrcTokTable age( FlatSESEEnterNode curr ) {
-
- VarSrcTokTable out = new VarSrcTokTable();
- /*
- Iterator<VariableSourceToken> itr = trueSet.iterator();
- while( itr.hasNext() ) {
- VariableSourceToken vst = itr.next();
- if( vst.getSESE().equals( curr ) ) {
- Integer newAge = vst.getAge()+1;
- if( newAge > MAX_AGE ) {
- newAge = MAX_AGE;
- }
- out.add( new VariableSourceToken( curr,
- vst.getVarLive(),
- newAge ) );
- } else {
- assert curr.getChildren().contains( vst.getSESE() );
- out.add( new VariableSourceToken( curr,
- vst.getVarLive(),
- new Integer( 1 ) ) );
- }
- }
- */
- return out;
- }
-
-
- public boolean equals( Object o ) {
- if( o == null ) {
- return false;
- }
-
- if( !(o instanceof VarSrcTokTable) ) {
- return false;
- }
-
- VarSrcTokTable table = (VarSrcTokTable) o;
- return trueSet.equals( table.trueSet );
- }
-
- public int hashCode() {
- return trueSet.hashCode();
- }
-
- public Iterator<VariableSourceToken> iterator() {
- return trueSet.iterator();
- }
-
- public String toString() {
- return "trueSet ="+trueSet.toString()+"\n"+
- "sese2vst="+sese2vst.toString()+"\n"+
- "var2vst ="+var2vst.toString()+"\n"+
- "sv2vst ="+sv2vst.toString();
- }
-}
+package Analysis.MLP;\r
+\r
+import IR.*;\r
+import IR.Flat.*;\r
+import java.util.*;\r
+import java.io.*;\r
+\r
+public class VarSrcTokTable {\r
+ \r
+ // the true set represents the set of (sese, variable, age)\r
+ // triples that are truly in the table\r
+ private HashSet<VariableSourceToken> trueSet;\r
+\r
+ // these hashtables provide an efficient retreival from the\r
+ // true set. Note that a particular triple from the quick\r
+ // look up must be checked against the true set--remove ops\r
+ // can cause the hashtables to be inconsistent to each other\r
+ private Hashtable< TempDescriptor, Set<VariableSourceToken> > var2vst;\r
+ private Hashtable< FlatSESEEnterNode, Set<VariableSourceToken> > sese2vst;\r
+ private Hashtable< SVKey, Set<VariableSourceToken> > sv2vst;\r
+\r
+ // maximum age from aging operation\r
+ private Integer MAX_AGE = new Integer( 2 );\r
+\r
+\r
+ public VarSrcTokTable() {\r
+ trueSet = new HashSet<VariableSourceToken>();\r
+\r
+ sese2vst = new Hashtable< FlatSESEEnterNode, Set<VariableSourceToken> >();\r
+ var2vst = new Hashtable< TempDescriptor, Set<VariableSourceToken> >();\r
+ sv2vst = new Hashtable< SVKey, Set<VariableSourceToken> >();\r
+ }\r
+\r
+ \r
+ public VarSrcTokTable( VarSrcTokTable in ) {\r
+ trueSet = (HashSet<VariableSourceToken>) in.trueSet.clone();\r
+\r
+ Iterator itr; Set s;\r
+\r
+ sese2vst = new Hashtable< FlatSESEEnterNode, Set<VariableSourceToken> >();\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
+ sese2vst.put( sese, \r
+ (HashSet<VariableSourceToken>) (s1.clone()) );\r
+ }\r
+\r
+ var2vst = new Hashtable< TempDescriptor, Set<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
+ var2vst.put( var, \r
+ (HashSet<VariableSourceToken>) (s1.clone()) );\r
+ }\r
+\r
+ sv2vst = new Hashtable< SVKey, Set<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
+ sv2vst.put( key, \r
+ (HashSet<VariableSourceToken>) (s1.clone()) );\r
+ }\r
+ }\r
+\r
+\r
+ public void add( VariableSourceToken vst ) {\r
+ trueSet.add( vst );\r
+\r
+ Set<VariableSourceToken> s;\r
+\r
+ s = sese2vst.get( vst.getSESE() );\r
+ if( s == null ) {\r
+ s = new HashSet<VariableSourceToken>();\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
+\r
+ SVKey key = new SVKey( vst.getSESE(), vst.getVarLive() );\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
+\r
+ public void addAll( Set<VariableSourceToken> s ) {\r
+ Iterator<VariableSourceToken> itr = s.iterator();\r
+ while( itr.hasNext() ) {\r
+ add( itr.next() );\r
+ }\r
+ }\r
+\r
+\r
+ public Set<VariableSourceToken> get() {\r
+ return trueSet;\r
+ }\r
+\r
+ public Set<VariableSourceToken> get( FlatSESEEnterNode sese ) {\r
+ Set<VariableSourceToken> s = sese2vst.get( sese );\r
+ if( s == null ) {\r
+ s = new HashSet<VariableSourceToken>(); \r
+ sese2vst.put( sese, s );\r
+ }\r
+ s.retainAll( trueSet );\r
+ return s;\r
+ }\r
+\r
+ public Set<VariableSourceToken> get( TempDescriptor var ) {\r
+ Set<VariableSourceToken> s = var2vst.get( var );\r
+ if( s == null ) {\r
+ s = new HashSet<VariableSourceToken>();\r
+ var2vst.put( var, s );\r
+ }\r
+ s.retainAll( trueSet );\r
+ return s;\r
+ }\r
+\r
+ public Set<VariableSourceToken> get( SVKey key ) {\r
+ Set<VariableSourceToken> s = sv2vst.get( key );\r
+ if( s == null ) {\r
+ s = new HashSet<VariableSourceToken>();\r
+ sv2vst.put( key, s );\r
+ }\r
+ s.retainAll( trueSet );\r
+ return s;\r
+ }\r
+\r
+\r
+ public void merge( VarSrcTokTable table ) {\r
+\r
+ if( table == null ) {\r
+ return;\r
+ }\r
+\r
+ trueSet.addAll( table.trueSet );\r
+\r
+ Iterator itr; \r
+ Set s;\r
+\r
+ itr = 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
+ 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
+\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
+ Set<VariableSourceToken> s2 = table.var2vst.get( var );\r
+ \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
+\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
+ Set<VariableSourceToken> s2 = table.sv2vst.get( key );\r
+ \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
+ }\r
+\r
+\r
+ public void remove( FlatSESEEnterNode sese ) {\r
+ Set<VariableSourceToken> s = sese2vst.get( sese );\r
+ if( s == null ) {\r
+ return;\r
+ }\r
+ \r
+ trueSet.removeAll( s ); \r
+ sese2vst.remove( sese );\r
+ }\r
+\r
+ public void remove( TempDescriptor var ) {\r
+ Set<VariableSourceToken> s = var2vst.get( var );\r
+ if( s == null ) {\r
+ return;\r
+ }\r
+ \r
+ trueSet.removeAll( s ); \r
+ var2vst.remove( var );\r
+ }\r
+\r
+ public void remove( FlatSESEEnterNode sese,\r
+ TempDescriptor var ) {\r
+\r
+ SVKey key = new SVKey( sese, var );\r
+ Set<VariableSourceToken> s = sv2vst.get( key );\r
+ if( s == null ) {\r
+ return;\r
+ }\r
+ \r
+ trueSet.removeAll( s );\r
+ sv2vst.remove( key );\r
+ }\r
+\r
+ public void remove( VariableSourceToken vst ) {\r
+ trueSet.remove( vst );\r
+ }\r
+\r
+\r
+ // return a new table based on this one and\r
+ // age tokens with respect to SESE curr, where\r
+ // any child becomes curr with age 0, and any\r
+ // curr tokens increase age by 1\r
+ public VarSrcTokTable age( FlatSESEEnterNode curr ) {\r
+\r
+ VarSrcTokTable out = new VarSrcTokTable();\r
+\r
+ Iterator<VariableSourceToken> itr = trueSet.iterator();\r
+ while( itr.hasNext() ) {\r
+ VariableSourceToken vst = itr.next();\r
+ if( vst.getSESE().equals( curr ) ) {\r
+ Integer newAge = vst.getAge()+1;\r
+ if( newAge > MAX_AGE ) {\r
+ newAge = MAX_AGE;\r
+ }\r
+ out.add( new VariableSourceToken( vst.getVarLive(), \r
+ curr, \r
+ newAge,\r
+ vst.getVarSrc() \r
+ )\r
+ );\r
+ } \r
+ }\r
+\r
+ return out;\r
+ }\r
+\r
+ \r
+ // for the given SESE, remove tokens for the same live\r
+ // variable if it comes from a child SESE\r
+ public VarSrcTokTable removeChildToks( FlatSESEEnterNode curr ) {\r
+\r
+ // create a table to modify as a copy of this\r
+ VarSrcTokTable out = new VarSrcTokTable( this );\r
+\r
+ // iterate over this table, modify out table\r
+ Iterator<VariableSourceToken> itr = get( curr ).iterator();\r
+ while( itr.hasNext() ) {\r
+ VariableSourceToken vst = itr.next();\r
+\r
+ Iterator<VariableSourceToken> itr2 = get( vst.getVarLive() ).iterator();\r
+ while( itr2.hasNext() ) {\r
+ VariableSourceToken vst2 = itr2.next();\r
+\r
+ if( curr.getChildren().contains( vst2.getSESE() ) ) {\r
+ out.remove( vst2 );\r
+ } \r
+ }\r
+ }\r
+\r
+ return out; \r
+ } \r
+\r
+\r
+ public boolean equals( Object o ) {\r
+ if( o == null ) {\r
+ return false;\r
+ }\r
+\r
+ if( !(o instanceof VarSrcTokTable) ) {\r
+ return false;\r
+ }\r
+\r
+ VarSrcTokTable table = (VarSrcTokTable) o;\r
+ return trueSet.equals( table.trueSet );\r
+ }\r
+\r
+ public int hashCode() {\r
+ return trueSet.hashCode();\r
+ }\r
+\r
+ public Iterator<VariableSourceToken> iterator() {\r
+ return trueSet.iterator();\r
+ }\r
+\r
+ public String toString() {\r
+ return "trueSet ="+trueSet.toString()+"\n"+\r
+ "sese2vst="+sese2vst.toString()+"\n"+\r
+ "var2vst ="+var2vst.toString()+"\n"+\r
+ "sv2vst ="+sv2vst.toString();\r
+ }\r
+}\r