/* This methods takes in a FlatMethod and returns a map from a
* FlatNode to the set of temps that are live into the FlatNode.*/
- public static Hashtable<FlatNode, Set<TempDescriptor>> computeLiveTemps(FlatMethod fm) {
- return computeLiveTemps(fm, null);
+ public static Hashtable<FlatNode, Set<TempDescriptor>> computeLiveTemps(FlatMethod fm, int threshold) {
+ return computeLiveTemps(fm, null, threshold);
}
- public static Hashtable<FlatNode, Set<TempDescriptor>> computeLiveTemps(FlatMethod fm, LocalityBinding lb) {
+ public static Hashtable<FlatNode, Set<TempDescriptor>> computeLiveTemps(FlatMethod fm, LocalityBinding lb, int threshold) {
Hashtable<FlatNode, Set<TempDescriptor>> nodetotemps=new Hashtable<FlatNode, Set<TempDescriptor>>();
Set<FlatNode> toprocess=fm.getNodeSet();
if (!nodetotemps.containsKey(fn)||
!nodetotemps.get(fn).equals(tempset)) {
nodetotemps.put(fn, tempset);
+ if(threshold!=-1 && nodetotemps.size()>threshold){
+ return null;
+ }
for(int i=0; i<fn.numPrev(); i++)
toprocess.add(fn.getPrev(i));
}
}
public static Hashtable<FlatNode, Set<TempDescriptor>> computeLiveOut(FlatMethod fm, LocalityBinding lb) {
- Hashtable<FlatNode, Set<TempDescriptor>> liveinmap=computeLiveTemps(fm, lb);
+ Hashtable<FlatNode, Set<TempDescriptor>> liveinmap=computeLiveTemps(fm, lb,-1);
Hashtable<FlatNode, Set<TempDescriptor>> liveoutmap=new Hashtable<FlatNode, Set<TempDescriptor>>();
for(Iterator<FlatNode> fnit=fm.getNodeSet().iterator(); fnit.hasNext();) {
public Set<TempDescriptor> getLiveInTemps( FlatMethod fm, FlatNode fn ) {
if( !fm2liveMap.containsKey( fm ) ) {
- fm2liveMap.put( fm, Liveness.computeLiveTemps( fm ) );
+ fm2liveMap.put( fm, Liveness.computeLiveTemps( fm,-1 ) );
}
return fm2liveMap.get( fm ).get( fn );
}
Set<TempDescriptor> liveinto=new HashSet<TempDescriptor>();
- Hashtable<FlatNode, Hashtable<TempDescriptor, Set<FlatNode>>> reachingdefs=ReachingDefs.computeReachingDefs(fm, Liveness.computeLiveTemps(fm), true);
+ Hashtable<FlatNode, Hashtable<TempDescriptor, Set<FlatNode>>> reachingdefs=ReachingDefs.computeReachingDefs(fm, Liveness.computeLiveTemps(fm,-1), true);
for(Iterator<FlatNode> fnit=secondpart.iterator(); fnit.hasNext(); ) {
FlatNode fn=fnit.next();
MethodDescriptor md=lb.getMethod();
FlatMethod fm=state.getMethodFlat(md);
Set<FlatNode> exits=faen.getExits();
- Hashtable<FlatNode, Set<TempDescriptor>> livemap=Liveness.computeLiveTemps(fm);
- Hashtable<FlatNode, Hashtable<TempDescriptor, Set<FlatNode>>> reachingdefs=ReachingDefs.computeReachingDefs(fm, Liveness.computeLiveTemps(fm), true);
+ Hashtable<FlatNode, Set<TempDescriptor>> livemap=Liveness.computeLiveTemps(fm,-1);
+ Hashtable<FlatNode, Hashtable<TempDescriptor, Set<FlatNode>>> reachingdefs=ReachingDefs.computeReachingDefs(fm, Liveness.computeLiveTemps(fm,-1), true);
Set<FlatNode> atomicnodes=faen.getReachableSet(faen.getExits());
MethodDescriptor md=lb.getMethod();
FlatMethod fm=state.getMethodFlat(md);
Set<FlatNode> exits=faen.getExits();
- Hashtable<FlatNode, Set<TempDescriptor>> livemap=Liveness.computeLiveTemps(fm);
+ Hashtable<FlatNode, Set<TempDescriptor>> livemap=Liveness.computeLiveTemps(fm,-1);
Hashtable<FlatNode, Hashtable<TempDescriptor, Set<FlatNode>>> reachingdefs=ReachingDefs.computeReachingDefs(fm, livemap, true);
Set<FlatNode> atomicnodes=faen.getReachableSet(faen.getExits());
derefset=derefmap.get(lb);
HashSet<FlatNode> otherset=othermap.get(lb);
HashSet<FlatNode> cannotdelayset=cannotdelaymap.get(lb);
- Hashtable<FlatNode,Set<TempDescriptor>> livemap=Liveness.computeLiveTemps(fm);
+ Hashtable<FlatNode,Set<TempDescriptor>> livemap=Liveness.computeLiveTemps(fm,-1);
Hashtable<FlatNode, Hashtable<TempDescriptor, Set<FlatNode>>> reachingdefsmap=ReachingDefs.computeReachingDefs(fm, livemap, true);
HashSet<FlatNode> unionset=new HashSet<FlatNode>(delayedset);
Hashtable<FlatNode, Hashtable<TempDescriptor, HashSet<FlatNode>>> map=new Hashtable<FlatNode, Hashtable<TempDescriptor, HashSet<FlatNode>>>();
MethodDescriptor md=lb.getMethod();
FlatMethod fm=state.getMethodFlat(md);
Hashtable<FlatNode, Integer> atomictable=locality.getAtomic(lb);
- Hashtable<FlatNode, Set<TempDescriptor>> livetemps=Liveness.computeLiveTemps(fm);
+ Hashtable<FlatNode, Set<TempDescriptor>> livetemps=Liveness.computeLiveTemps(fm,-1);
tovisit.add(fm);
discovered.add(fm);
MethodDescriptor md=lb.getMethod();
FlatMethod fm=state.getMethodFlat(md);
Hashtable<FlatNode, Integer> atomictable=locality.getAtomic(lb);
- Hashtable<FlatNode, Set<TempDescriptor>> livetemps=Liveness.computeLiveTemps(fm);
+ Hashtable<FlatNode, Set<TempDescriptor>> livetemps=Liveness.computeLiveTemps(fm,-1);
tovisit.add(fm);
discovered.add(fm);
}
}
- Hashtable<FlatNode, Set<TempDescriptor>> livemap=Liveness.computeLiveTemps(fm);
+ Hashtable<FlatNode, Set<TempDescriptor>> livemap=Liveness.computeLiveTemps(fm,-1);
while(!tovisit.isEmpty()) {
FlatNode fn=tovisit.iterator().next();
Hashtable<FlatNode, Hashtable<TempDescriptor, Integer>> temptab=getNodeTempInfo(lb);
MethodDescriptor md=lb.getMethod();
FlatMethod fm=state.getMethodFlat(md);
- Hashtable<FlatNode, Set<TempDescriptor>> nodetotemps=Liveness.computeLiveTemps(fm);
+ Hashtable<FlatNode, Set<TempDescriptor>> nodetotemps=Liveness.computeLiveTemps(fm,-1);
Hashtable<FlatAtomicEnterNode, Set<TempDescriptor>> nodetosavetemps=new Hashtable<FlatAtomicEnterNode, Set<TempDescriptor>>();
tempstosave.put(lb, nodetosavetemps);
Hashtable<FlatNode, FlatAtomicEnterNode> nodemap=new Hashtable<FlatNode, FlatAtomicEnterNode>();
}
}
Hashtable<Expression, TempDescriptor> tab=computeIntersection(fn, availexpr);
-
+
+// if(tab.size()>1000){
+// System.out.println("Skipping CSE of "+fm.getMethod()+" due to size.");
+// return;
+// }
+
//Do kills of expression/variable mappings
TempDescriptor[] write=fn.writesTemps();
for(int i=0; i<write.length; i++) {
- if (tab.containsKey(write[i]))
- tab.remove(write[i]);
+ for(Iterator it=tab.entrySet().iterator(); it.hasNext(); ) {
+ Map.Entry m=(Map.Entry)it.next();
+ TempDescriptor td=(TempDescriptor)m.getValue();
+ if(td.equals(write[i])){
+ it.remove();
+ }
+ }
}
+
+
+
switch(fn.kind()) {
case FKind.FlatAtomicEnterNode:
}
public void optimize(FlatMethod fm) {
- Hashtable<FlatNode, Set<TempDescriptor>> livetemps=Liveness.computeLiveTemps(fm);
Hashtable<FlatNode, Hashtable<TempDescriptor, TempDescriptor>> table
=new Hashtable<FlatNode, Hashtable<TempDescriptor, TempDescriptor>>();
boolean changed=false;
TempDescriptor bogustd=new TempDescriptor("bogus");
do {
+ Hashtable<FlatNode, Set<TempDescriptor>> livetemps=Liveness.computeLiveTemps(fm,1000);
+ if(livetemps==null){
+ System.out.println("Skipping CopyPropagation of "+fm.getMethod()+" due to size.");
+ return;
+ }
changed=false;
HashSet tovisit=new HashSet();
tovisit.add(fm);
while(!tovisit.isEmpty()) {
FlatNode fn=(FlatNode) tovisit.iterator().next();
tovisit.remove(fn);
-
Hashtable<TempDescriptor, TempDescriptor> tab;
- if (fn.numPrev()>=1&&table.containsKey(fn.getPrev(0)))
- tab=new Hashtable<TempDescriptor, TempDescriptor>(table.get(fn.getPrev(0)));
- else
+ Set<TempDescriptor> liveset=livetemps.get(fn);
+
+ if (fn.numPrev()>=1&&table.containsKey(fn.getPrev(0))) {
+ tab=new Hashtable<TempDescriptor, TempDescriptor>();
+ for(Map.Entry<TempDescriptor, TempDescriptor> entry:table.get(fn.getPrev(0)).entrySet()) {
+ if (liveset.contains(entry.getKey())) {
+ tab.put(entry.getKey(), entry.getValue());
+ }
+ }
+ } else
tab=new Hashtable<TempDescriptor, TempDescriptor>();
//Compute intersection
- Set<TempDescriptor> liveset=livetemps.get(fn);
for(int i=1; i<fn.numPrev(); i++) {
Hashtable<TempDescriptor, TempDescriptor> tp=table.get(fn.getPrev(i));
if (tp==null)
continue;
TempDescriptor dsttmp=tp.get(tmp);
if (!tab.containsKey(tmp)) {
- tab.put(tmp, dsttmp);
+ tab.put(tmp, dsttmp);
} else if (tab.get(tmp)!=dsttmp) {
tab.put(tmp, bogustd);
}
}
}
-
+
HashSet<TempDescriptor> toremove=new HashSet<TempDescriptor>();
TempDescriptor[] writes=fn.writesTemps();
for(int i=0; i<writes.length; i++) {
public void analyze(FlatMethod fm) {
Hashtable<FlatNode, Set<TempFlatPair>> tmp=new Hashtable<FlatNode, Set<TempFlatPair>>();
HashSet<FlatNode> toanalyze=new HashSet<FlatNode>();
- Hashtable<FlatNode, Set<TempDescriptor>> livemap=Liveness.computeLiveTemps(fm);
+ Hashtable<FlatNode, Set<TempDescriptor>> livemap=Liveness.computeLiveTemps(fm,-1);
toanalyze.addAll(fm.getNodeSet());
while(!toanalyze.isEmpty()) {
FlatNode fn=toanalyze.iterator().next();
public BasicBlock getBBlock(FlatMethod fm) {
if (!blockMap.containsKey(fm)) {
blockMap.put(fm, BasicBlock.getBBlock(fm));
- Hashtable<FlatNode, Set<TempDescriptor>> livemap=Liveness.computeLiveTemps(fm);
+ Hashtable<FlatNode, Set<TempDescriptor>> livemap=Liveness.computeLiveTemps(fm,-1);
for(BBlock bblock : blockMap.get(fm).getBlocks()) {
FlatNode fn=bblock.nodes.get(0);
if (fn==fm) {