Commit 72d3f5cb authored by Carlos Galindo's avatar Carlos Galindo
Browse files

ConstrainedTabularAlgorithm: lookup table to speedup summary generation

Also implemented in subsumed version.
parent 130f01d9
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ public class ConstrainedSubsumedTabularAlgorithm extends ConstrainedTabularAlgor
    @Override
    public Set<Node> slice(Node node) {
        subLookupMap = new HashMap<>();
        current2worksMap = new HashMap<>();
        return super.slice(node);
    }

@@ -46,6 +47,7 @@ public class ConstrainedSubsumedTabularAlgorithm extends ConstrainedTabularAlgor
                workList.add(work);
                // Populate subLookupMap
                subLookupMap.computeIfAbsent(wns, k -> new HashSet<>()).add(work);
                current2worksMap.computeIfAbsent(work.current(), k -> new HashSet<>()).add(work);
            }
        }
    }
+7 −9
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ public class ConstrainedTabularAlgorithm implements SlicingAlgorithm {
    protected PriorityQueue<Work> workList;
    /** Works that have been reached throughout the traversal. */
    protected Set<Work> pathEdge;
    protected Map<State, Set<Work>> current2worksMap;

    public ConstrainedTabularAlgorithm(EDG edg) {
        this.edg = edg;
@@ -46,6 +47,7 @@ public class ConstrainedTabularAlgorithm implements SlicingAlgorithm {
    public Set<Node> slice(Node node) {
        workList = new PriorityQueue<>();
        pathEdge = new HashSet<>();
        current2worksMap = new HashMap<>();
        propagate(new Work(new State(node, new Constraints())));
        workTheList();
        return pathEdge.stream().map(w -> w.current.node).collect(Collectors.toSet());
@@ -63,8 +65,10 @@ public class ConstrainedTabularAlgorithm implements SlicingAlgorithm {
     * Add a new Work to be processed, only if it hasn't been visited before.
     */
    protected void propagate(Work work) {
        if (pathEdge.add(work))
        if (pathEdge.add(work)) {
            workList.add(work);
            current2worksMap.computeIfAbsent(work.current, k -> new HashSet<>()).add(work);
        }
    }

    protected void workTheList() {
@@ -152,15 +156,9 @@ public class ConstrainedTabularAlgorithm implements SlicingAlgorithm {
                    State actualIn = new State(aInNode, formalIn.stack);
                    State actualOut = new State(aOutNode, formalOut.stack);
                    if (!summaryEdges.containsKey(actualOut) || !summaryEdges.get(actualOut).contains(actualIn)) {
                        if (!summaryEdges.containsKey(actualOut))
                            summaryEdges.put(actualOut, new HashSet<>());
                        summaryEdges.get(actualOut).add(actualIn);
                        Set<Work> reached = new HashSet<>();
                        for (Work w : pathEdge)
                            if (actualOut.equals(w.current))
                                reached.add(w);
                        for (Work w : reached)
                        for (Work w : current2worksMap.getOrDefault(actualOut, new HashSet<>()))
                            propagate(new Work(w, actualIn));
                        summaryEdges.computeIfAbsent(actualOut, k -> new HashSet<>()).add(actualIn);
                    }
                }
            }