tabulation API generalization

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@2532 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2008-02-04 21:01:34 +00:00
parent 84e00a667a
commit c38525d185
6 changed files with 34 additions and 46 deletions

View File

@ -12,8 +12,6 @@ package com.ibm.wala.dataflow.IFDS;
import java.util.Collection;
import com.ibm.wala.util.collections.Pair;
/**
*
* Representation of a Dyck-language graph reachability problem for the
@ -41,10 +39,9 @@ public interface TabulationProblem<T,P> {
public IFlowFunctionMap<T> getFunctionMap();
/**
* Define the set of facts that are live on entry to the analysis. Each fact represents a dataflow
* factoid number (Integer) at a particular supergraph node (T).
* Define the set of path edges to start propagation with.
*/
public Collection<Pair<T,Integer>> initialSeeds();
public Collection<PathEdge<T>> initialSeeds();
/**
* Special case: if supportsMerge(), then the problem is not really IFDS

View File

@ -29,7 +29,6 @@ import com.ibm.wala.util.collections.HashMapFactory;
import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.collections.Heap;
import com.ibm.wala.util.collections.Iterator2Collection;
import com.ibm.wala.util.collections.Pair;
import com.ibm.wala.util.collections.ToStringComparator;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.heapTrace.HeapTracer;
@ -188,8 +187,8 @@ public class TabulationSolver<T, P> {
* Start tabulation with the initial seeds.
*/
protected void initialize() {
for (Pair<T, Integer> seed : problem.initialSeeds()) {
propagate(seed.fst, seed.snd, seed.fst, seed.snd);
for (PathEdge<T> seed : problem.initialSeeds()) {
propagate(seed.entry, seed.d1, seed.target, seed.d2);
}
}

View File

@ -13,11 +13,12 @@ package com.ibm.wala.ipa.slicer;
import com.ibm.wala.ipa.callgraph.CGNode;
/**
* A statement representing method entry, used for managing
* control dependence
* A statement representing method entry, used for managing control dependence.
*
* This is also used as a dummy entry for starting propagation to a seed statement.
*
* @author sjfink
*
*
*/
public class MethodEntryStatement extends Statement {
@ -31,7 +32,7 @@ public class MethodEntryStatement extends Statement {
return false;
}
if (getClass().equals(obj.getClass())) {
MethodEntryStatement other = (MethodEntryStatement)obj;
MethodEntryStatement other = (MethodEntryStatement) obj;
return getNode().equals(other.getNode());
} else {
return false;
@ -40,12 +41,12 @@ public class MethodEntryStatement extends Statement {
@Override
public Kind getKind() {
return Kind.METHOD_ENTRY;
return Kind.METHOD_ENTRY;
}
@Override
public int hashCode() {
return getKind().hashCode() + 9901*getNode().hashCode();
return getKind().hashCode() + 9901 * getNode().hashCode();
}
@Override

View File

@ -119,14 +119,11 @@ public class PDG implements NumberedGraph<Statement> {
private boolean isPopulated = false;
/**
* @param mod
* the set of heap locations which may be written (transitively) by this node. These are logically return
* values in the SDG.
* @param ref
* the set of heap locations which may be read (transitively) by this node. These are logically parameters
* in the SDG.
* @throws IllegalArgumentException
* if node is null
* @param mod the set of heap locations which may be written (transitively) by this node. These are logically return
* values in the SDG.
* @param ref the set of heap locations which may be read (transitively) by this node. These are logically parameters
* in the SDG.
* @throws IllegalArgumentException if node is null
*/
public PDG(final CGNode node, PointerAnalysis pa, Map<CGNode, OrdinalSet<PointerKey>> mod,
Map<CGNode, OrdinalSet<PointerKey>> ref, DataDependenceOptions dOptions, ControlDependenceOptions cOptions,
@ -135,14 +132,11 @@ public class PDG implements NumberedGraph<Statement> {
}
/**
* @param mod
* the set of heap locations which may be written (transitively) by this node. These are logically return
* values in the SDG.
* @param ref
* the set of heap locations which may be read (transitively) by this node. These are logically parameters
* in the SDG.
* @throws IllegalArgumentException
* if node is null
* @param mod the set of heap locations which may be written (transitively) by this node. These are logically return
* values in the SDG.
* @param ref the set of heap locations which may be read (transitively) by this node. These are logically parameters
* in the SDG.
* @throws IllegalArgumentException if node is null
*/
public PDG(final CGNode node, PointerAnalysis pa, Map<CGNode, OrdinalSet<PointerKey>> mod,
Map<CGNode, OrdinalSet<PointerKey>> ref, DataDependenceOptions dOptions, ControlDependenceOptions cOptions,
@ -448,7 +442,7 @@ public class PDG implements NumberedGraph<Statement> {
Assertions.UNREACHABLE();
}
// TODO: this is overly conservative. deal with catch blocks?
for (IntIterator ii = getPEIs(ir).intIterator(); ii.hasNext(); ) {
for (IntIterator ii = getPEIs(ir).intIterator(); ii.hasNext();) {
int index = ii.next();
SSAInstruction pei = ir.getInstructions()[index];
if (dOptions.isTerminateAtCast() && (pei instanceof SSACheckCastInstruction)) {
@ -720,7 +714,8 @@ public class PDG implements NumberedGraph<Statement> {
return ssaInstruction2Statement(node, s, instructionIndices);
}
public static synchronized Statement ssaInstruction2Statement(CGNode node, SSAInstruction s, Map<SSAInstruction, Integer> instructionIndices) {
public static synchronized Statement ssaInstruction2Statement(CGNode node, SSAInstruction s,
Map<SSAInstruction, Integer> instructionIndices) {
assert s != null;
if (s instanceof SSAPhiInstruction) {
SSAPhiInstruction phi = (SSAPhiInstruction) s;
@ -800,17 +795,14 @@ public class PDG implements NumberedGraph<Statement> {
createCalleeParams(ref);
createReturnStatements();
if (!cOptions.equals(ControlDependenceOptions.NONE)) {
delegate.addNode(new MethodEntryStatement(node));
}
delegate.addNode(new MethodEntryStatement(node));
}
/**
* create nodes representing defs of the return values
*
* @param mod
* the set of heap locations which may be written (transitively) by this node. These are logically
* parameters in the SDG.
* @param mod the set of heap locations which may be written (transitively) by this node. These are logically
* parameters in the SDG.
* @param dOptions
*/
private void createReturnStatements() {
@ -839,9 +831,8 @@ public class PDG implements NumberedGraph<Statement> {
/**
* create nodes representing defs of formal parameters
*
* @param ref
* the set of heap locations which may be read (transitively) by this node. These are logically parameters
* in the SDG.
* @param ref the set of heap locations which may be read (transitively) by this node. These are logically parameters
* in the SDG.
*/
private void createCalleeParams(Map<CGNode, OrdinalSet<PointerKey>> ref) {
ArrayList<Statement> list = new ArrayList<Statement>();

View File

@ -178,7 +178,7 @@ class SDGSupergraph implements ISupergraph<Statement, PDG> {
*/
public Statement getMainEntry() {
Assertions.productionAssertion(!backward, "todo: support backward");
return srcStatement;
return new MethodEntryStatement(srcStatement.getNode());
}
/*
@ -188,7 +188,7 @@ class SDGSupergraph implements ISupergraph<Statement, PDG> {
// We pretend that sink is the "main exit" .. we don't care about
// flow past the sink.
Assertions.productionAssertion(backward, "todo: support forward");
return srcStatement;
return new MethodEntryStatement(srcStatement.getNode());
}
/*

View File

@ -18,6 +18,7 @@ import com.ibm.wala.dataflow.IFDS.BackwardsSupergraph;
import com.ibm.wala.dataflow.IFDS.IFlowFunctionMap;
import com.ibm.wala.dataflow.IFDS.IMergeFunction;
import com.ibm.wala.dataflow.IFDS.ISupergraph;
import com.ibm.wala.dataflow.IFDS.PathEdge;
import com.ibm.wala.dataflow.IFDS.TabulationDomain;
import com.ibm.wala.dataflow.IFDS.TabulationProblem;
import com.ibm.wala.dataflow.IFDS.TabulationResult;
@ -28,7 +29,6 @@ import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis;
import com.ibm.wala.ipa.modref.ModRef;
import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.collections.Iterator2Collection;
import com.ibm.wala.util.collections.Pair;
import com.ibm.wala.util.debug.Assertions;
/**
@ -419,8 +419,8 @@ public class Slicer {
return supergraph;
}
public Collection<Pair<Statement, Integer>> initialSeeds() {
Pair<Statement,Integer> seed = Pair.make(src, 0);
public Collection<PathEdge<Statement>> initialSeeds() {
PathEdge<Statement> seed = PathEdge.createPathEdge(new MethodEntryStatement(src.getNode()), 0, src, 0);
return Collections.singleton(seed);
}
}