/** * Traverse the statements in the given body, looking for aggregation possibilities; that is, * given a def d and a use u, d has no other uses, u has no other defs, collapse d and u. * * <p>option: only-stack-locals; if this is true, only aggregate variables starting with $ */ protected void internalTransform(Body b, String phaseName, Map<String, String> options) { StmtBody body = (StmtBody) b; boolean onlyStackVars = PhaseOptions.getBoolean(options, "only-stack-locals"); int aggregateCount = 1; if (Options.v().time()) Timers.v().aggregationTimer.start(); boolean changed = false; Map<ValueBox, Zone> boxToZone = new HashMap<ValueBox, Zone>(body.getUnits().size() * 2 + 1, 0.7f); // Determine the zone of every box { Zonation zonation = new Zonation(body); for (Unit u : body.getUnits()) { Zone zone = zonation.getZoneOf(u); for (ValueBox box : u.getUseBoxes()) { boxToZone.put(box, zone); } for (ValueBox box : u.getDefBoxes()) { boxToZone.put(box, zone); } } } do { if (Options.v().verbose()) G.v() .out .println( "[" + body.getMethod().getName() + "] Aggregating iteration " + aggregateCount + "..."); // body.printTo(new java.io.PrintWriter(G.v().out, true)); changed = internalAggregate(body, boxToZone, onlyStackVars); aggregateCount++; } while (changed); if (Options.v().time()) Timers.v().aggregationTimer.end(); }
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); } }
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(); }