public void doAnalysis() {
toprocess.add(buildInitialContext());
-
while(!toprocess.isEmpty()) {
Delta delta=toprocess.remove();
PPoint ppoint=delta.getBlock();
BBlock bblock=ppoint.getBBlock();
Vector<FlatNode> nodes=bblock.nodes();
int startindex=0;
+
if (ppoint.getIndex()==-1) {
//Build base graph for entrance to this basic block
delta=applyInitDelta(delta, bblock);
startindex=ppoint.getIndex()+1;
delta=applyCallDelta(delta, bblock);
}
-
Graph graph=bbgraphMap.get(bblock);
Graph nodeGraph=null;
//Compute delta at exit of each node
for(int i=startindex; i<nodes.size();i++) {
FlatNode currNode=nodes.get(i);
+
if (!graphMap.containsKey(currNode)) {
graphMap.put(currNode, new Graph(graph));
}
}
//DEBUG
- int debugindex=0;
- for(Map.Entry<BBlock, Graph> e:bbgraphMap.entrySet()) {
- Graph g=e.getValue();
- try {
- PrintWriter pw=new PrintWriter(new FileWriter("BB"+debugindex+".dot"));
- g.printGraph(pw, "BB");
- pw.close();
- } catch (Exception ex) {
- ex.printStackTrace();
+ if (false) {
+ int debugindex=0;
+ for(Map.Entry<BBlock, Graph> e:bbgraphMap.entrySet()) {
+ Graph g=e.getValue();
+ plotGraph(g,"BB"+debugindex);
+ debugindex++;
}
- debugindex++;
- }
-
- for(Map.Entry<FlatNode, Graph> e:graphMap.entrySet()) {
- FlatNode fn=e.getKey();
- Graph g=e.getValue();
- try {
- PrintWriter pw=new PrintWriter(new FileWriter("FN"+fn.toString().replace(' ','_')+".dot"));
- g.printGraph(pw, fn.toString());
- pw.close();
- } catch (Exception ex) {
- ex.printStackTrace();
+
+ for(Map.Entry<FlatNode, Graph> e:graphMap.entrySet()) {
+ FlatNode fn=e.getKey();
+ Graph g=e.getValue();
+ plotGraph(g,"FN"+fn.toString()+debugindex);
+ debugindex++;
+ }
+ for(FlatMethod fm:blockMap.keySet()) {
+ fm.printMethod();
}
- debugindex++;
}
+ }
+ void plotGraph(Graph g, String name) {
+ try {
+ PrintWriter pw=new PrintWriter(new FileWriter(name.toString().replace(' ','_')+".dot"));
+ g.printGraph(pw, name);
+ pw.close();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
}
+
/* This function builds the last delta for a basic block. It
* handles the case for the first time the basic block is
/* Start with the new incoming edges */
MySet<Edge> newbaseedge=delta.basevaredge.get(tmp);
/* Remove the remove set */
+ if (newbaseedge==null)
+ newbaseedge=new MySet<Edge>();
newbaseedge.removeAll(delta.varedgeremove.get(tmp));
/* Add in the new set*/
newbaseedge.addAll(delta.varedgeadd.get(tmp));
/* Store the results */
newDelta.varedgeadd.put(tmp, newbaseedge);
}
+ delta.basevaredge.clear();
/* Next we build heap edges */
HashSet<AllocNode> nodeSet=new HashSet<AllocNode>();
nodeSet.addAll(delta.heapedgeremove.keySet());
for(AllocNode node:nodeSet) {
/* Start with the new incoming edges */
- MySet<Edge> newheapedge=(MySet<Edge>) delta.baseheapedge.get(node).clone();
+ MySet<Edge> newheapedge=new MySet<Edge>(delta.baseheapedge.get(node));
/* Remove the remove set */
MySet<Edge> removeset=delta.heapedgeremove.get(node);
/* Now we need to propagate newdelta */
if (!newDelta.heapedgeadd.isEmpty()||!newDelta.heapedgeremove.isEmpty()||!newDelta.varedgeadd.isEmpty()||!newDelta.addNodeAges.isEmpty()||!newDelta.addOldNodes.isEmpty()) {
/* We have a delta to propagate */
- Vector<BBlock> blockvector=bblock.next();
- for(int i=0;i<blockvector.size();i++) {
- if (i==0) {
- newDelta.setBlock(new PPoint(blockvector.get(i)));
- toprocess.add(newDelta);
- } else {
- toprocess.add(newDelta.diffBlock(new PPoint(blockvector.get(i))));
+ if (returnMap.containsKey(bblock)) {
+ //exit of call block
+ boolean first=true;
+
+ for(PPoint caller:returnMap.get(bblock)) {
+ if (first) {
+ newDelta.setBlock(caller);
+ toprocess.add(newDelta);
+ first=false;
+ } else {
+ Delta d=newDelta.diffBlock(caller);
+ toprocess.add(d);
+ }
+ }
+ } else {
+ //normal block
+ Vector<BBlock> blockvector=bblock.next();
+ for(int i=0;i<blockvector.size();i++) {
+ if (i==0) {
+ newDelta.setBlock(new PPoint(blockvector.get(i)));
+ toprocess.add(newDelta);
+ } else {
+ Delta d=newDelta.diffBlock(new PPoint(blockvector.get(i)));
+ toprocess.add(d);
+ }
}
}
}
return processSetFieldElementNode(node, delta, newgraph);
case FKind.FlatMethod:
case FKind.FlatExit:
+ case FKind.FlatBackEdge:
+ case FKind.FlatGenReachNode:
+ case FKind.FlatSESEEnterNode:
+ case FKind.FlatSESEExitNode:
return processFlatNop(node, delta, newgraph);
case FKind.FlatCall:
return processFlatCall(bblock, index, (FlatCall) node, delta, newgraph);
- case FKind.FlatSESEEnterNode:
- case FKind.FlatSESEExitNode:
- throw new Error("Unimplemented node:"+node);
default:
throw new Error("Unrecognized node:"+node);
}
//Need to push existing results to current node
if (returnDelta==null) {
returnDelta=new Delta(null, false);
- buildInitDelta(bbgraphMap.get(block.getExit()), returnDelta);
+ Vector<FlatNode> exitblocknodes=block.getExit().nodes();
+ FlatExit fexit=(FlatExit)exitblocknodes.get(exitblocknodes.size()-1);
+ buildInitDelta(graphMap.get(fexit), returnDelta);
if (!returnDelta.heapedgeadd.isEmpty()||!returnDelta.heapedgeremove.isEmpty()||!returnDelta.varedgeadd.isEmpty()) {
returnDelta.setBlock(new PPoint(callblock, callindex));
toprocess.add(returnDelta);
for(TempDescriptor tmp:temps) {
//Compute set of edges from given node
MySet<Edge> edges=new MySet<Edge>(delta.basevaredge.get(tmp));
+
edges.removeAll(delta.varedgeremove.get(tmp));
edges.addAll(delta.varedgeadd.get(tmp));
delta.removeEdge(e);
}
}
-
Delta processFlatCall(BBlock callblock, int callindex, FlatCall fcall, Delta delta, Graph graph) {
Delta newDelta=new Delta(null, false);
Graph oldgraph=(ppoint.getIndex()==0)?
bbgraphMap.get(bblock):
graphMap.get(nodes.get(ppoint.getIndex()-1));
-
+
//Age outside nodes if necessary
for(Iterator<AllocNode> nodeit=delta.addNodeAges.iterator();nodeit.hasNext();) {
AllocNode node=nodeit.next();
summarizeInGraph(graph, newDelta, node);
}
}
-
//Add heap edges in
for(Map.Entry<AllocNode, MySet<Edge>> entry:delta.heapedgeadd.entrySet()) {
for(Edge e:entry.getValue()) {
mergeEdge(graph, newDelta, edgetoadd);
}
}
-
//Add external edges in
for(Edge e:graph.externalEdgeSet) {
//First did we age the source
}
//Add edge for return value
if (fcall.getReturnTemp()!=null) {
- MySet<Edge> returnedge=newDelta.varedgeadd.get(returntmp);
- for(Edge e:returnedge) {
- Edge newedge=e.copy();
- newedge.srcvar=fcall.getReturnTemp();
- if (graph.getEdges(fcall.getReturnTemp())==null||!graph.getEdges(fcall.getReturnTemp()).contains(newedge))
- newDelta.addEdge(newedge);
- }
+ MySet<Edge> returnedge=delta.varedgeadd.get(returntmp);
+ if (returnedge!=null)
+ for(Edge e:returnedge) {
+ Edge newedge=e.copy();
+ newedge.srcvar=fcall.getReturnTemp();
+ if (graph.getEdges(fcall.getReturnTemp())==null||!graph.getEdges(fcall.getReturnTemp()).contains(newedge))
+ newDelta.addEdge(newedge);
+ }
}
-
applyDiffs(graph, newDelta);
return newDelta;
}
if (match==null||!match.subsumes(edgetoadd)) {
Edge mergededge=edgetoadd.merge(match);
- newDelta.addHeapEdge(mergededge);
+ newDelta.addEdge(mergededge);
}
}
}
} else {
//Generate diff from parent graph
MySet<Edge> parentedges=graph.parent.nodeMap.get(node);
- MySet<Edge> newedgeset=Util.setSubtract(parentedges, edgestoremove);
- graph.nodeMap.put(node, newedgeset);
+ if (parentedges!=null) {
+ MySet<Edge> newedgeset=Util.setSubtract(parentedges, edgestoremove);
+ graph.nodeMap.put(node, newedgeset);
+ }
}
}
if (delta.getInit()) {
HashSet<AllocNode> srcNodes=GraphManip.getNodes(graph, delta, src);
HashSet<AllocNode> dstNodes=GraphManip.getNodes(graph, delta, dst);
- MySet<Edge> edgesToAdd=GraphManip.genEdges(srcNodes, fd, dstNodes);
+ MySet<Edge> edgesToAdd=GraphManip.genEdges(dstNodes, fd, srcNodes);
MySet<Edge> edgesToRemove=null;
- if (srcNodes.size()==1&&!srcNodes.iterator().next().isSummary()) {
+ if (dstNodes.size()==1&&!dstNodes.iterator().next().isSummary()&&fd!=null) {
/* Can do a strong update */
- edgesToRemove=GraphManip.getEdges(graph, delta, srcNodes, fd);
- }
+ edgesToRemove=GraphManip.getEdges(graph, delta, dstNodes, fd);
+ graph.strongUpdateSet=edgesToRemove;
+ } else
+ graph.strongUpdateSet=new MySet<Edge>();
/* Update diff */
updateHeapDelta(graph, delta, edgesToAdd, edgesToRemove);
applyDiffs(graph, delta);
MySet<Edge> edgesToRemove=null;
- if (newSrcNodes.size()!=0) {
- if (srcNodes.size()==1&&!srcNodes.iterator().next().isSummary()) {
+ if (newDstNodes.size()!=0) {
+ if (dstNodes.size()>1&&!dstNodes.iterator().next().isSummary()&&fd!=null) {
/* Need to undo strong update */
if (graph.strongUpdateSet!=null) {
edgesToAdd.addAll(graph.strongUpdateSet);
- graph.strongUpdateSet.clear();
+ graph.strongUpdateSet=null; //Prevent future strong updates
}
- } else if (srcNodes.size()==0&&newSrcNodes.size()==1&&!newSrcNodes.iterator().next().isSummary()&&graph.strongUpdateSet==null) {
- edgesToRemove=GraphManip.getEdges(graph, delta, srcNodes, fd);
+ } else if (dstNodes.size()==1&&newDstNodes.size()==1&&!newDstNodes.iterator().next().isSummary()&&graph.strongUpdateSet!=null&&fd!=null) {
+ edgesToRemove=GraphManip.getEdges(graph, delta, dstNodes, fd);
+ graph.strongUpdateSet.addAll(edgesToRemove);
}
- edgesToAdd.addAll(GraphManip.genEdges(newSrcNodes, fd, dstNodes));
+ edgesToAdd.addAll(GraphManip.genEdges(newDstNodes, fd, srcNodes));
+ }
+
+ //Kill new edges
+ if (graph.strongUpdateSet!=null&&fd!=null) {
+ MySet<Edge> otherEdgesToRemove=GraphManip.getDiffEdges(delta, dstNodes);
+ if (edgesToRemove!=null)
+ edgesToRemove.addAll(otherEdgesToRemove);
+ else
+ edgesToRemove=otherEdgesToRemove;
+ graph.strongUpdateSet.addAll(otherEdgesToRemove);
}
//Next look at new destinations
- edgesToAdd.addAll(GraphManip.genEdges(srcNodes, fd, newDstNodes));
+ edgesToAdd.addAll(GraphManip.genEdges(dstNodes, fd, newSrcNodes));
/* Update diff */
updateHeapDelta(graph, delta, edgesToAdd, edgesToRemove);
FlatReturnNode frn=(FlatReturnNode)node;
src=frn.getReturnTemp();
dst=returntmp;
- if (src==null) {
+ if (src==null||!src.getType().isPtr()) {
//This is a NOP
applyDiffs(graph, delta);
return delta;
}
if (delta.getInit()) {
HashSet<AllocNode> srcnodes=GraphManip.getNodes(graph, delta, src);
- MySet<Edge> edgesToAdd=GraphManip.genEdges(src, srcnodes);
+ MySet<Edge> edgesToAdd=GraphManip.genEdges(dst, srcnodes);
MySet<Edge> edgesToRemove=GraphManip.getEdges(graph, delta, dst);
updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
applyDiffs(graph, delta);
HashSet<AllocNode> newSrcNodes=GraphManip.getDiffNodes(delta, src);
/* Compute the union, and then the set of edges */
- MySet<Edge> edgesToAdd=GraphManip.genEdges(src, newSrcNodes);
+ MySet<Edge> edgesToAdd=GraphManip.genEdges(dst, newSrcNodes);
/* Compute set of edges to remove */
MySet<Edge> edgesToRemove=GraphManip.getDiffEdges(delta, dst);
if (delta.getInit()) {
HashSet<AllocNode> srcnodes=GraphManip.getNodes(graph, delta, src);
HashSet<AllocNode> fdnodes=GraphManip.getNodes(graph, delta, srcnodes, fd);
- MySet<Edge> edgesToAdd=GraphManip.genEdges(src, fdnodes);
+ MySet<Edge> edgesToAdd=GraphManip.genEdges(dst, fdnodes);
MySet<Edge> edgesToRemove=GraphManip.getEdges(graph, delta, dst);
updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
applyDiffs(graph, delta);
HashSet<AllocNode> newTargets=new HashSet<AllocNode>();
newTargets.addAll(newfdnodes);
newTargets.addAll(difffdnodes);
- MySet<Edge> edgesToAdd=GraphManip.genEdges(src, newTargets);
+ MySet<Edge> edgesToAdd=GraphManip.genEdges(dst, newTargets);
/* Compute set of edges to remove */
MySet<Edge> edgesToRemove=GraphManip.getDiffEdges(delta, dst);
MySet<Edge> edgeAdd=delta.heapedgeadd.get(src);
MySet<Edge> existingEdges=graph.getEdges(src);
//remove edge from delta
- edgeAdd.remove(e);
+ if (edgeAdd!=null)
+ edgeAdd.remove(e);
//if the edge is already in the graph, add an explicit remove to the delta
if (existingEdges.contains(e)) {
delta.removeHeapEdge(e);
//Add it into the diffs
delta.varedgeadd.put(tmp, newedges);
//Remove the old edges
- delta.varedgeremove.put(tmp, graph.getEdges(tmp));
+ delta.varedgeremove.put(tmp, (MySet<Edge>) graph.getEdges(tmp).clone());
//Apply incoming diffs to graph
applyDiffs(graph, delta);
//Note that we create a single node
removeSet=new MySet<Edge>();
}
- removeSet.add(e.copy());
+ removeSet.add(e);
+ e=e.copy();
if (e.dst==oldnode)
e.dst=newnode;
if (e.src==oldnode)
mergeVarEdges(graph, delta, newdelta);
mergeAges(graph, delta, newdelta);
}
+
return newdelta;
}
}
}
//Done with edge set...
- if (diffedges.size()>=0) {
+ if (diffedges.size()>0) {
//completely new
newdelta.basevaredge.put(tmpsrc,diffedges);
}