/** * given a DelayabilityAnalysis and the computations of each unit, calculates the latest * computation-point for each expression.<br> * the <code>equivRhsMap</code> could be calculated on the fly, but it is <b>very</b> likely that * it already exists (as similar maps are used for calculating Earliestness, Delayed,...<br> * the shared set allows more efficient set-operations, when they the computation is merged with * other analyses/computations. * * @param dg a ExceptionalUnitGraph * @param delayed the delayability-analysis of the same graph. * @param equivRhsMap all computations of the graph * @param set the shared flowSet */ public LatestComputation( UnitGraph unitGraph, DelayabilityAnalysis delayed, Map equivRhsMap, BoundedFlowSet set) { unitToLatest = new HashMap<Unit, FlowSet>(unitGraph.size() + 1, 0.7f); Iterator unitIt = unitGraph.iterator(); while (unitIt.hasNext()) { /* create a new Earliest-list for each unit */ Unit currentUnit = (Unit) unitIt.next(); /* basically the latest-set is: * (delayed) INTERSECT (comp UNION (UNION_successors ~Delayed)) = * (delayed) MINUS ((INTERSECTION_successors Delayed) MINUS comp). */ FlowSet delaySet = (FlowSet) delayed.getFlowBefore(currentUnit); /* Calculate (INTERSECTION_successors Delayed) */ FlowSet succCompSet = (FlowSet) set.topSet(); List succList = unitGraph.getSuccsOf(currentUnit); Iterator succIt = succList.iterator(); while (succIt.hasNext()) { Unit successor = (Unit) succIt.next(); succCompSet.intersection((FlowSet) delayed.getFlowBefore(successor), succCompSet); } /* remove the computation of this set: succCompSet is then: * ((INTERSECTION_successors Delayed) MINUS comp) */ if (equivRhsMap.get(currentUnit) != null) succCompSet.remove(equivRhsMap.get(currentUnit)); /* make the difference: */ FlowSet latest = (FlowSet) delaySet.emptySet(); delaySet.difference(succCompSet, latest); unitToLatest.put(currentUnit, latest); } }
/** * Computes the analysis given a UnitGraph computed from a method body. It is recommended that a * ExceptionalUnitGraph (or similar) be provided for correct results in the case of exceptional * control flow. * * @param g a graph on which to compute the analysis. * @see ExceptionalUnitGraph */ public SimpleLiveLocals(UnitGraph graph) { if (Options.v().time()) Timers.v().liveTimer.start(); if (Options.v().verbose()) G.v() .out .println( "[" + graph.getBody().getMethod().getName() + "] Constructing SimpleLiveLocals..."); SimpleLiveLocalsAnalysis analysis = new SimpleLiveLocalsAnalysis(graph); if (Options.v().time()) Timers.v().livePostTimer.start(); // Build unitToLocals map { unitToLocalsAfter = new HashMap<Unit, List>(graph.size() * 2 + 1, 0.7f); unitToLocalsBefore = new HashMap<Unit, List>(graph.size() * 2 + 1, 0.7f); Iterator unitIt = graph.iterator(); while (unitIt.hasNext()) { Unit s = (Unit) unitIt.next(); FlowSet set = (FlowSet) analysis.getFlowBefore(s); unitToLocalsBefore.put(s, Collections.unmodifiableList(set.toList())); set = (FlowSet) analysis.getFlowAfter(s); unitToLocalsAfter.put(s, Collections.unmodifiableList(set.toList())); } } if (Options.v().time()) Timers.v().livePostTimer.end(); if (Options.v().time()) Timers.v().liveTimer.end(); }
SimpleLiveLocalsAnalysis(UnitGraph g) { super(g); if (Options.v().time()) Timers.v().liveSetupTimer.start(); emptySet = new ArraySparseSet(); // Create kill sets. { unitToKillSet = new HashMap<Unit, FlowSet>(g.size() * 2 + 1, 0.7f); Iterator unitIt = g.iterator(); while (unitIt.hasNext()) { Unit s = (Unit) unitIt.next(); FlowSet killSet = emptySet.clone(); Iterator boxIt = s.getDefBoxes().iterator(); while (boxIt.hasNext()) { ValueBox box = (ValueBox) boxIt.next(); if (box.getValue() instanceof Local) killSet.add(box.getValue(), killSet); } unitToKillSet.put(s, killSet); } } // Create generate sets { unitToGenerateSet = new HashMap<Unit, FlowSet>(g.size() * 2 + 1, 0.7f); Iterator unitIt = g.iterator(); while (unitIt.hasNext()) { Unit s = (Unit) unitIt.next(); FlowSet genSet = emptySet.clone(); Iterator boxIt = s.getUseBoxes().iterator(); while (boxIt.hasNext()) { ValueBox box = (ValueBox) boxIt.next(); if (box.getValue() instanceof Local) genSet.add(box.getValue(), genSet); } unitToGenerateSet.put(s, genSet); } } if (Options.v().time()) Timers.v().liveSetupTimer.end(); if (Options.v().time()) Timers.v().liveAnalysisTimer.start(); doAnalysis(); if (Options.v().time()) Timers.v().liveAnalysisTimer.end(); }