public class Liveness {
/* This methods takes in a FlatMethod and returns a map from a
- * FlatNode to the set of live temps for that FlatNode.*/
+ * FlatNode to the set of temps that are live into the FlatNode.*/
public static Hashtable<FlatNode, Set<TempDescriptor>> computeLiveTemps(FlatMethod fm) {
Hashtable<FlatNode, Set<TempDescriptor>> nodetotemps=new Hashtable<FlatNode, Set<TempDescriptor>>();
secondpart.retainAll(atomicnodes);
Set<TempDescriptor> liveinto=new HashSet<TempDescriptor>();
- Hashtable<FlatNode, Hashtable<TempDescriptor, Set<FlatNode>>> reachingdefs=ReachingDefs.computeReachingDefs(fm);
+
+ Hashtable<FlatNode, Hashtable<TempDescriptor, Set<FlatNode>>> reachingdefs=ReachingDefs.computeReachingDefs(fm, Liveness.computeLiveTemps(fm));
for(Iterator<FlatNode> fnit=secondpart.iterator();fnit.hasNext();) {
FlatNode fn=fnit.next();
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);
-
+ Hashtable<FlatNode, Hashtable<TempDescriptor, Set<FlatNode>>> reachingdefs=ReachingDefs.computeReachingDefs(fm, Liveness.computeLiveTemps(fm));
+
Set<FlatNode> atomicnodes=faen.getReachableSet(faen.getExits());
Set<FlatNode> secondpart=new HashSet<FlatNode>(getNotReady(lb));
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);
+ Hashtable<FlatNode, Hashtable<TempDescriptor, Set<FlatNode>>> reachingdefs=ReachingDefs.computeReachingDefs(fm, livemap);
Set<FlatNode> atomicnodes=faen.getReachableSet(faen.getExits());
for(Iterator<TempDescriptor> tmpit=tempset.iterator();tmpit.hasNext();) {
TempDescriptor tmp=tmpit.next();
Set<FlatNode> fnset=reachmap.get(tmp);
+ if (fnset==null) {
+ System.out.println("null temp set for"+fn+" tmp="+tmp);
+ System.out.println(fm.printMethod());
+ }
for(Iterator<FlatNode> fnit2=fnset.iterator();fnit2.hasNext();) {
FlatNode fn2=fnit2.next();
if (secondpart.contains(fn2)) {
/* This methods takes in a FlatMethod and returns a map from a
* FlatNode to the set of live temps for that FlatNode.*/
- public static Hashtable<FlatNode, Hashtable<TempDescriptor, Set<FlatNode>>> computeReachingDefs(FlatMethod fm) {
+ public static Hashtable<FlatNode, Hashtable<TempDescriptor, Set<FlatNode>>> computeReachingDefs(FlatMethod fm, Hashtable<FlatNode, Set<TempDescriptor>> livemap) {
Hashtable<FlatNode, Hashtable<TempDescriptor, Set<FlatNode>>> nodetotemps=new Hashtable<FlatNode, Hashtable<TempDescriptor,Set<FlatNode>>>();
Set<FlatNode> toprocess=fm.getNodeSet();
Hashtable<TempDescriptor, Set<FlatNode>> tempset=new Hashtable<TempDescriptor, Set<FlatNode>>();
+ Set<TempDescriptor> livetempset=livemap.get(fn);
+
for(int i=0; i<fn.numPrev(); i++) {
FlatNode fnprev=fn.getPrev(i);
if (nodetotemps.containsKey(fnprev)) {
Hashtable<TempDescriptor,Set<FlatNode>> prevtable=nodetotemps.get(fnprev);
for(Iterator<TempDescriptor> tmpit=prevtable.keySet().iterator();tmpit.hasNext();) {
TempDescriptor tmp=tmpit.next();
+ if (!livetempset.contains(tmp))
+ continue;
if (!tempset.containsKey(tmp))
tempset.put(tmp, new HashSet<FlatNode>());
tempset.get(tmp).addAll(prevtable.get(tmp));
}
public TempDescriptor [] readsTemps() {
- return new TempDescriptor[] {src};
+ if (!makePtr&&!convert)
+ return new TempDescriptor[0];
+ else
+ return new TempDescriptor[] {src};
}
}
return flatExit;
}
+ public void check() {
+ Set<FlatNode> set=getNodeSet();
+ for(Iterator<FlatNode> setit=set.iterator();setit.hasNext();) {
+ FlatNode fn=setit.next();
+ for(int i=0;i<fn.numPrev();i++) {
+ FlatNode fnprev=fn.getPrev(i);
+ if (!set.contains(fnprev)) {
+ System.out.println(fn+" has unreachable parent:"+i+" "+fnprev);
+ System.out.println(printMethod());
+ throw new Error();
+
+ }
+ }
+ }
+ }
+
/** This method returns a set of the nodes in this flat representation */
public Set<FlatNode> getNodeSet() {
visited.add(fn);
for(int i=0; i<fn.numNext(); i++) {
FlatNode nn=fn.getNext(i);
+ if (nn==null)
+ continue;
if (!visited.contains(nn))
tovisit.add(nn);
}
import java.util.Iterator;
public class FlatNode {
- protected Vector next;
+ public Vector next;
protected Vector prev;
public FlatNode() {
}
for(int i=0;i<next.size();i++) {
FlatNode nnext=(FlatNode)next.get(i);
- fnnew.next.set(i,nnext);;
+ fnnew.next.set(i,nnext);
for(int j=0;j<nnext.numPrev();j++) {
FlatNode n=nnext.getPrev(j);
if (n==this)
nnext.prev.set(j, fnnew);
}
}
+ next=null;
+ prev=null;
}
}
return new TempDescriptor(name+"_"+currentid, type, tag);
}
+ public TempDescriptor createNew(String x) {
+ if (tag==null)
+ return new TempDescriptor(name+"_"+currentid+"_"+x, type);
+ else
+ return new TempDescriptor(name+"_"+currentid+"_"+x, type, tag);
+ }
+
public static TempDescriptor tempFactory() {
return new TempDescriptor("temp_"+currentid);
}
void dc_t_chashInsertOnce(void * key, void *val) {
chashlistnode_t *ptr;
+ if (key==NULL)
+ return;
if(dc_c_numelements > (dc_c_threshold)) {
//Resize