コード例 #1
0
ファイル: LatestComputation.java プロジェクト: richardxx/soot
  /**
   * 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);
    }
  }
コード例 #2
0
 public void calculateOutSet(Unit u, BoundedFlowSet inSet, BoundedFlowSet outSet) {
   // If the def set is a subset of the in set, then out = in \ impure use, else
   // out = (in union def) \ use
   BoundedFlowSet defSet = defSetMap.get(u);
   BoundedFlowSet inComplement = (BoundedFlowSet) inSet.clone();
   inComplement.complement();
   inComplement.intersection(defSet);
   if (inComplement.size() == 0) {
     inSet.copy(outSet);
     outSet.difference(useSetMap.get(u));
   } else {
     inSet.union(defSet, outSet);
     outSet.difference(useSetMap.get(u));
   }
 }
コード例 #3
0
  public FaintVariableAnalysis(Body body) {

    Chain<Local> locals = body.getLocals();

    allVariables = new CollectionFlowUniverse<Local>(locals);

    universalSet = new ArrayPackedSet(allVariables);

    for (Local l : locals) universalSet.add(l);

    useSetMap = new HashMap<Unit, BoundedFlowSet>();
    defSetMap = new HashMap<Unit, BoundedFlowSet>();

    UnitGraph graph = new BriefUnitGraph(body);
    for (Unit u : graph) {

      BoundedFlowSet defSet = new ArrayPackedSet(allVariables);
      BoundedFlowSet useSet = new ArrayPackedSet(allVariables);

      for (ValueBox v : u.getDefBoxes()) {
        // Only do this for locals. We're not going to even try to handle anything
        // other than locals.
        if (v.getValue() instanceof Local) {
          defSet.add(v.getValue());
        }
      }
      for (ValueBox v : u.getUseBoxes()) {
        // Only do this for locals. We're not going to even try to handle anything
        // other than locals.
        if (v.getValue() instanceof Local) {
          useSet.add(v.getValue());
        }
      }

      defSetMap.put(u, defSet);
      useSetMap.put(u, useSet);
    }
  }
コード例 #4
0
 public void mergeOutSets(List<BoundedFlowSet> outSets, BoundedFlowSet inSet) {
   // Take the intersection of the out sets as the in set.
   for (BoundedFlowSet set : outSets) inSet.intersection(set);
 }
コード例 #5
0
 public BoundedFlowSet createOutSet(Unit u) {
   // Initial value for the out set is the universal set
   return (BoundedFlowSet) universalSet.clone();
 }