package Analysis.Pointer;
+import IR.Flat.*;
+import IR.*;
+import Analysis.Pointer.AllocFactory.AllocNode;
+import java.util.*;
public class GraphManip {
static HashSet<Edge> genEdges(TempDescriptor tmp, HashSet<AllocNode> dstSet) {
return edges;
}
+ static HashSet<Edge> getEdges(Graph graph, Delta delta, HashSet<AllocNode> srcNodes, FieldDescriptor fd) {
+ HashSet<Edge> nodes=new HashSet<Edge>();
+ for(AllocNode node:srcNodes) {
+ HashSet<Edge> removeedges=delta.heapedgeremove.get(node);
+ for(Edge e:graph.getEdges(node)) {
+ if (e.fd==fd&&(removeedges==null||!removeedges.contains(e)))
+ nodes.add(e);
+ }
+ if (delta.heapedgeadd.containsKey(node))
+ for(Edge e:delta.heapedgeadd.get(node)) {
+ if (e.fd==fd)
+ nodes.add(e);
+ }
+ }
+ return nodes;
+ }
+
static HashSet<AllocNode> getDiffNodes(Delta delta, TempDescriptor tmp) {
HashSet<AllocNode> nodes=new HashSet<AllocNode>();
HashSet<Edge> removeedges=delta.varedgeremove.get(tmp);
if (delta.getInit()) {
HashSet<AllocNode> srcNodes=GraphManip.getNodes(graph, delta, src);
HashSet<AllocNode> dstNodes=GraphManip.getNodes(graph, delta, dst);
- HashSet<Edges> edgesToAdd=GraphManip.genEdges(srcNodes, fd, dstNodes);
+ HashSet<Edge> edgesToAdd=GraphManip.genEdges(srcNodes, fd, dstNodes);
+ HashSet<Edge> edgesToRemove=null;
if (dstNodes.size()==1&&!dstNodes.iterator().next().isSummary()) {
/* Can do a strong update */
-
-
+ edgesToRemove=GraphManip.getEdges(graph, delta, dstNodes, fd);
}
+ /* Update diff */
+ updateHeapDelta(graph, delta, edgesToAdd, edgesToRemove);
+ applyDiffs(graph, delta);
} else {
-
-
+ /* First look at new sources */
+ HashSet<Edge> edgesToAdd=new HashSet<Edge>();
+ HashSet<AllocNode> newSrcNodes=GraphManip.getDiffNodes(delta, src);
+ HashSet<AllocNode> dstNodes=GraphManip.getDiffNodes(delta, dst);
+ edgesToAdd.addAll(GraphManip.genEdges(newSrcNodes, fd, dstNodes));
+ HashSet<AllocNode> newDstNodes=GraphManip.getDiffNodes(delta, dst);
+ HashSet<Edge> edgesToRemove=null;
+ if (newDstNodes.size()!=0) {
+ if (dstNodes.size()==1&&!dstNodes.iterator().next().isSummary()) {
+ /* Need to undo strong update */
+ if (graph.strongUpdateSet!=null) {
+ edgesToAdd.addAll(graph.strongUpdateSet);
+ graph.strongUpdateSet.clear();
+ }
+ } else if (dstNodes.size()==0&&newDstNodes.size()==1&&!newDstNodes.iterator().next().isSummary()&&graph.strongUpdateSet==null) {
+ edgesToRemove=GraphManip.getEdges(graph, delta, dstNodes, fd);
+ }
+ HashSet<AllocNode> srcNodes=GraphManip.getDiffNodes(delta, src);
+ edgesToAdd.addAll(GraphManip.genEdges(srcNodes, fd, newDstNodes));
+ }
+ /* Update diff */
+ updateHeapDelta(graph, delta, edgesToAdd, edgesToRemove);
+ applyDiffs(graph, delta);
}
+ return delta;
}
Delta processCopyNode(FlatNode node, Delta delta, Graph graph) {
TempDescriptor dst;
if (node.kind()==FKind.FlatOpNode) {
FlatOpNode fon=(FlatOpNode) node;
- src=fcn.getLeft();
- dst=fcn.getDst();
+ src=fon.getLeft();
+ dst=fon.getDest();
} else {
FlatCastNode fcn=(FlatCastNode) node;
src=fcn.getSrc();
}
static void updateHeapDelta(Graph graph, Delta delta, HashSet<Edge> edgestoAdd, HashSet<Edge> edgestoRemove) {
- /* Fix all of this */
- HashSet<Edge> edgeAdd=delta.varedgeadd.get(tmp);
- HashSet<Edge> edgeRemove=delta.varedgeremove.get(tmp);
- HashSet<Edge> existingEdges=graph.getEdges(tmp);
for(Edge e: edgestoRemove) {
+ AllocNode src=e.src;
+ HashSet<Edge> edgeAdd=delta.heapedgeadd.get(src);
+ HashSet<Edge> existingEdges=graph.getEdges(src);
//remove edge from delta
edgeAdd.remove(e);
//if the edge is already in the graph, add an explicit remove to the delta
- if (existingEdges.contains(e))
+ if (existingEdges.contains(e)) {
+ HashSet<Edge> edgeRemove=delta.heapedgeremove.get(src);
edgeRemove.add(e);
+ }
}
for(Edge e: edgestoAdd) {
+ AllocNode src=e.src;
+ HashSet<Edge> edgeRemove=delta.heapedgeremove.get(src);
+ HashSet<Edge> existingEdges=graph.getEdges(src);
//Remove the edge from the remove set
edgeRemove.remove(e);
//Explicitly add it to the add set unless it is already in the graph
- if (!existingEdges.contains(e))
+ if (!existingEdges.contains(e)) {
+ HashSet<Edge> edgeAdd=delta.heapedgeadd.get(src);
edgeAdd.add(e);
+ }
}
}
for(Map.Entry<AllocNode, HashSet<Edge>> entry:addheapedge.entrySet()) {
AllocNode allocnode=entry.getKey();
- Util.relationUpdate(delta.heapedgeadd, allocnode, null. entry.getValue());
+ Util.relationUpdate(delta.heapedgeadd, allocnode, null, entry.getValue());
}
/* 4. Fix up the base heap edges */