From: bdemsky Date: Sat, 22 Jan 2011 06:27:41 +0000 (+0000) Subject: beginning of points-to analysis X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=283a8c810e9d3e2d59fd09c4d9729c2cb1c0382b;p=IRC.git beginning of points-to analysis --- diff --git a/Robust/src/Analysis/Pointer/AllocFactory.java b/Robust/src/Analysis/Pointer/AllocFactory.java new file mode 100644 index 00000000..74a4f20e --- /dev/null +++ b/Robust/src/Analysis/Pointer/AllocFactory.java @@ -0,0 +1,48 @@ +package Analysis.Pointer; + +import java.util.*; +import IR.*; +import IR.Flat.*; + +public class AllocFactory { + public static class AllocNode { + int allocsite; + boolean summary; + TypeDescriptor type; + + public AllocNode(int allocsite, TypeDescriptor type, boolean summary) { + this.allocsite=allocsite; + this.summary=summary; + this.type=type; + } + + public int hashCode() { + return allocsite<<1^(summary?0:1); + } + + public boolean equals(Object o) { + if (o instanceof AllocNode) { + AllocNode an=(AllocNode)o; + return (allocsite==an.allocsite)&&(summary==an.summary); + } + return false; + } + } + + public AllocFactory(State state, TypeUtil typeUtil) { + allocMap=new HashMap(); + this.typeUtil=typeUtil; + ClassDescriptor stringcd=typeUtil.getClass(TypeUtil.StringClass); + TypeDescriptor stringtd=new TypeDescriptor(stringcd); + TypeDescriptor stringarraytd=stringtd.makeArray(state); + StringArray=new AllocNode(0, stringarraytd, false); + Strings=new AllocNode(1, stringtd, true); + } + + HashMap allocMap; + TypeUtil typeUtil; + int siteCounter=2; + + public AllocNode StringArray; + public AllocNode Strings; +} \ No newline at end of file diff --git a/Robust/src/Analysis/Pointer/BasicBlock.java b/Robust/src/Analysis/Pointer/BasicBlock.java new file mode 100644 index 00000000..deb93469 --- /dev/null +++ b/Robust/src/Analysis/Pointer/BasicBlock.java @@ -0,0 +1,96 @@ +package Analysis.Pointer; +import Analysis.Disjoint.PointerMethod; +import java.util.*; +import IR.Flat.*; + +public class BasicBlock { + public BBlock start; + public BBlock exit; + + public BasicBlock(BBlock start, BBlock exit) { + this.start=start; + this.exit=exit; + } + + public BBlock getStart() { + return start; + } + + public BBlock getExit() { + return exit; + } + + public static class BBlock { + Vector nodes; + Vector prevb; + Vector nextb; + + public BBlock() { + nodes=new Vector(); + prevb=new Vector(); + nextb=new Vector(); + } + + public Vector nodes() { + return nodes; + } + public Vector next() { + return nextb; + } + public Vector prev() { + return prevb; + } + } + + public static BasicBlock getBBlock(FlatMethod fm) { + BBlock exit=null; + Stack toprocess=new Stack(); + HashMap map=new HashMap(); + PointerMethod pm=new PointerMethod(); + pm.analyzeMethod(fm); + toprocess.add(fm); + map.put(fm, new BBlock()); + + while(!toprocess.isEmpty()) { + FlatNode fn=toprocess.pop(); + BBlock block=map.get(fn); + block.nodes.add(fn); + if (fn.kind()==FKind.FlatExit) + exit=block; + do { + if (pm.numNext(fn)!=1) { + for(int i=0;i1) { + //new basic block + if (!map.containsKey(fn)) { + map.put(fn, new BBlock()); + toprocess.add(fn); + } + //link block in + if (!block.nextb.contains(map.get(fn))) { + block.nextb.add(map.get(fn)); + map.get(fn).prevb.add(block); + } + break; + } + block.nodes.add(fn); + } while(true); + } + + return new BasicBlock(map.get(fm), exit); + } +} diff --git a/Robust/src/Analysis/Pointer/Delta.java b/Robust/src/Analysis/Pointer/Delta.java new file mode 100644 index 00000000..67b94143 --- /dev/null +++ b/Robust/src/Analysis/Pointer/Delta.java @@ -0,0 +1,48 @@ +package Analysis.Pointer; +import java.util.*; +import Analysis.Pointer.AllocFactory.AllocNode; +import Analysis.Pointer.BasicBlock.BBlock; +import IR.Flat.*; + +public class Delta { + HashMap> heapedgeremove; + HashMap> varedgeremove; + HashMap> heapedgeadd; + HashMap> varedgeadd; + + boolean init; + BBlock block; + + public Delta(BBlock block, boolean init) { + this.heapedgeadd=new HashMap>(); + this.varedgeadd=new HashMap>(); + this.heapedgeremove=new HashMap>(); + this.varedgeremove=new HashMap>(); + this.init=init; + this.block=block; + } + + public void addHeapEdge(AllocNode node, Edge e) { + if (!heapedgeadd.containsKey(node)) + heapedgeadd.put(node, new Vector()); + heapedgeadd.get(node).add(e); + } + + public void addVarEdge(TempDescriptor tmp, Edge e) { + if (!varedgeadd.containsKey(tmp)) + varedgeadd.put(tmp, new Vector()); + varedgeadd.get(tmp).add(e); + } + + public void setBlock(BBlock block) { + this.block=block; + } + + public BBlock getBlock() { + return block; + } + + public boolean getInit() { + return init; + } +} \ No newline at end of file diff --git a/Robust/src/Analysis/Pointer/Edge.java b/Robust/src/Analysis/Pointer/Edge.java new file mode 100644 index 00000000..5048f830 --- /dev/null +++ b/Robust/src/Analysis/Pointer/Edge.java @@ -0,0 +1,23 @@ +package Analysis.Pointer; +import IR.Flat.*; +import IR.*; +import Analysis.Pointer.AllocFactory.AllocNode; + +public class Edge { + FieldDescriptor fd; + AllocNode src; + TempDescriptor srcvar; + AllocNode dst; + + public Edge(AllocNode src, FieldDescriptor fd, AllocNode dst) { + this.src=src; + this.fd=fd; + this.dst=dst; + } + + public Edge(TempDescriptor tmp, AllocNode dst) { + this.srcvar=tmp; + this.dst=dst; + } + +} \ No newline at end of file diff --git a/Robust/src/Analysis/Pointer/Graph.java b/Robust/src/Analysis/Pointer/Graph.java new file mode 100644 index 00000000..d4969e9b --- /dev/null +++ b/Robust/src/Analysis/Pointer/Graph.java @@ -0,0 +1,29 @@ +package Analysis.Pointer; +import java.util.*; +import Analysis.Disjoint.PointerMethod; +import Analysis.Pointer.AllocFactory.AllocNode; +import IR.Flat.*; + +public class Graph { + + /* This is field is set is this Graph is just a delta on the parent + * graph. */ + + Graph parent; + HashSet tempset; + HashSet allocset; + + HashMap> nodeMap; + HashMap> tmpMap; + + public Graph(Graph parent) { + nodeMap=new HashMap>(); + tmpMap=new HashMap>(); + tempset=new HashSet(); + allocset=new HashSet(); + + this.parent=parent; + } + + +} \ No newline at end of file diff --git a/Robust/src/Analysis/Pointer/Pointer.java b/Robust/src/Analysis/Pointer/Pointer.java new file mode 100644 index 00000000..4987ac80 --- /dev/null +++ b/Robust/src/Analysis/Pointer/Pointer.java @@ -0,0 +1,81 @@ +package Analysis.Pointer; +import java.util.*; +import IR.Flat.*; +import IR.*; +import Analysis.Pointer.BasicBlock.BBlock; +import Analysis.Pointer.AllocFactory.AllocNode; + +public class Pointer { + HashMap blockMap; + HashMap graphMap; + State state; + TypeUtil typeUtil; + AllocFactory allocFactory; + LinkedList toprocess; + + public Pointer(State state, TypeUtil typeUtil) { + this.state=state; + this.blockMap=new HashMap(); + this.graphMap=new HashMap(); + this.typeUtil=typeUtil; + this.allocFactory=new AllocFactory(state, typeUtil); + this.toprocess=new LinkedList(); + } + + public BasicBlock getBBlock(FlatMethod fm) { + if (!blockMap.containsKey(fm)) + blockMap.put(fm, BasicBlock.getBBlock(fm)); + return blockMap.get(fm); + } + + Delta buildInitialContext() { + MethodDescriptor md=typeUtil.getMain(); + FlatMethod fm=state.getMethodFlat(md); + BasicBlock bb=getBBlock(fm); + BBlock start=bb.getStart(); + Delta delta=new Delta(start, true); + delta.addHeapEdge(allocFactory.StringArray, new Edge(allocFactory.StringArray, null, allocFactory.Strings)); + delta.addVarEdge(fm.getParameter(0), new Edge(fm.getParameter(0), allocFactory.StringArray)); + return delta; + } + + void doAnalysis() { + toprocess.add(buildInitialContext()); + + while(!toprocess.isEmpty()) { + Delta delta=toprocess.remove(); + BBlock bblock=delta.getBlock(); + Vector nodes=bblock.nodes(); + FlatNode firstNode=nodes.get(0); + + //Get graph for first node + if (!graphMap.containsKey(firstNode)) { + graphMap.put(firstNode, new Graph(null)); + } + Graph graph=graphMap.get(firstNode); + + //First entrance is special... + if (delta.getInit()) { + applyInit(delta, graph); + } else { + applyDelta(delta, graph); + } + + Graph nodeGraph=null; + for(int i=1; i