diff --git a/src/org/jruby/compiler/ir/compiler_pass/LiveVariableAnalysis.java b/src/org/jruby/compiler/ir/compiler_pass/LiveVariableAnalysis.java index ed9b9c039f7..4612fe04fcd 100644 --- a/src/org/jruby/compiler/ir/compiler_pass/LiveVariableAnalysis.java +++ b/src/org/jruby/compiler/ir/compiler_pass/LiveVariableAnalysis.java @@ -1,6 +1,5 @@ package org.jruby.compiler.ir.compiler_pass; -import org.jruby.compiler.ir.IRClosure; import org.jruby.compiler.ir.IRScope; import org.jruby.compiler.ir.dataflow.analyses.LiveVariablesProblem; @@ -10,15 +9,9 @@ public boolean isPreOrder() { } public void run(IRScope scope) { - LiveVariablesProblem lvp = new LiveVariablesProblem(); - String lvpName = lvp.getName(); - - lvp.setup(scope); + LiveVariablesProblem lvp = new LiveVariablesProblem(scope); lvp.compute_MOP_Solution(); + scope.setDataFlowSolution(lvp.getName(), lvp); -// System.out.println("LVP for " + s + " is: " + lvp); - for (IRClosure x: scope.getClosures()) { - lvp = (LiveVariablesProblem) x.getDataFlowSolution(lvpName); - } } } diff --git a/src/org/jruby/compiler/ir/compiler_pass/opts/DeadCodeElimination.java b/src/org/jruby/compiler/ir/compiler_pass/opts/DeadCodeElimination.java index 803856c8a1c..62c2ae1b7f2 100644 --- a/src/org/jruby/compiler/ir/compiler_pass/opts/DeadCodeElimination.java +++ b/src/org/jruby/compiler/ir/compiler_pass/opts/DeadCodeElimination.java @@ -15,8 +15,7 @@ public void run(IRScope scope) { LiveVariablesProblem lvp = (LiveVariablesProblem) scope.getDataFlowSolution(DataFlowConstants.LVP_NAME); if (lvp == null) { - lvp = new LiveVariablesProblem(); - lvp.setup(scope); + lvp = new LiveVariablesProblem(scope); lvp.compute_MOP_Solution(); scope.setDataFlowSolution(lvp.getName(), lvp); } diff --git a/src/org/jruby/compiler/ir/dataflow/DataFlowConstants.java b/src/org/jruby/compiler/ir/dataflow/DataFlowConstants.java index 2accb386e42..90def71fa43 100644 --- a/src/org/jruby/compiler/ir/dataflow/DataFlowConstants.java +++ b/src/org/jruby/compiler/ir/dataflow/DataFlowConstants.java @@ -10,7 +10,7 @@ import org.jruby.compiler.ir.representations.InlinerInfo; public class DataFlowConstants { - public static final String LVP_NAME = (new LiveVariablesProblem()).getName(); + public static final String LVP_NAME = LiveVariablesProblem.NAME; public static final String BLP_NAME = (new BindingLoadPlacementProblem()).getName(); public static final String BSP_NAME = (new BindingStorePlacementProblem()).getName(); diff --git a/src/org/jruby/compiler/ir/dataflow/analyses/LiveVariableNode.java b/src/org/jruby/compiler/ir/dataflow/analyses/LiveVariableNode.java index d4bf43e13e9..6d8eef8960d 100644 --- a/src/org/jruby/compiler/ir/dataflow/analyses/LiveVariableNode.java +++ b/src/org/jruby/compiler/ir/dataflow/analyses/LiveVariableNode.java @@ -99,8 +99,7 @@ public boolean applyTransferFunction() { IRClosure cl = ((WrappedIRClosure)o).getClosure(); LiveVariablesProblem cl_lvp = (LiveVariablesProblem)cl.getDataFlowSolution(DataFlowConstants.LVP_NAME); if (cl_lvp == null) { - cl_lvp = new LiveVariablesProblem(); - cl_lvp.setup(cl, lvp.getNonSelfLocalVars()); + cl_lvp = new LiveVariablesProblem(cl, lvp.getNonSelfLocalVars()); cl.setDataFlowSolution(cl_lvp.getName(), cl_lvp); } @@ -367,7 +366,7 @@ BitSet getLiveInBitSet() { } BitSet getLiveOutBitSet() { - return this.out; + return out; } private BitSet in; // Variables live at entry of this node diff --git a/src/org/jruby/compiler/ir/dataflow/analyses/LiveVariablesProblem.java b/src/org/jruby/compiler/ir/dataflow/analyses/LiveVariablesProblem.java index d282268d0e6..95dadd85b5d 100644 --- a/src/org/jruby/compiler/ir/dataflow/analyses/LiveVariablesProblem.java +++ b/src/org/jruby/compiler/ir/dataflow/analyses/LiveVariablesProblem.java @@ -1,12 +1,5 @@ package org.jruby.compiler.ir.dataflow.analyses; -import org.jruby.compiler.ir.dataflow.DataFlowProblem; -import org.jruby.compiler.ir.dataflow.DataFlowVar; -import org.jruby.compiler.ir.dataflow.FlowGraphNode; -import org.jruby.compiler.ir.operands.Variable; -import org.jruby.compiler.ir.operands.LocalVariable; -import org.jruby.compiler.ir.representations.BasicBlock; - import java.util.ArrayList; import java.util.BitSet; import java.util.Collection; @@ -15,12 +8,27 @@ import java.util.List; import java.util.Set; import org.jruby.compiler.ir.IRScope; +import org.jruby.compiler.ir.dataflow.DataFlowProblem; +import org.jruby.compiler.ir.dataflow.DataFlowVar; +import org.jruby.compiler.ir.dataflow.FlowGraphNode; +import org.jruby.compiler.ir.operands.LocalVariable; +import org.jruby.compiler.ir.operands.Variable; +import org.jruby.compiler.ir.representations.BasicBlock; public class LiveVariablesProblem extends DataFlowProblem { - public LiveVariablesProblem() { - super(DataFlowProblem.DF_Direction.BACKWARD); + public static final String NAME = "Live Variables Analysis"; + private static final Set EMPTY_SET = new HashSet(); + + public LiveVariablesProblem(IRScope scope) { + this(scope, EMPTY_SET); } + LiveVariablesProblem(IRScope scope, Set nonSelfLocalVars) { + super(DataFlowProblem.DF_Direction.BACKWARD); + + setup(scope, nonSelfLocalVars); + } + public DataFlowVar getDFVar(Variable v) { return dfVarMap.get(v); } @@ -88,10 +96,8 @@ public void setup(IRScope scope, Collection allVars) { setup(scope); - if ((allVars != null) && !allVars.isEmpty()) { - for (Variable v : allVars) { - if (getDFVar(v) == null) addDFVar(v); - } + for (Variable v : allVars) { + if (getDFVar(v) == null) addDFVar(v); } } @@ -128,7 +134,7 @@ public Set getNonSelfLocalVars() { } public String getName() { - return "Live Variables Analysis"; + return NAME; } /* ----------- Private Interface ------------ */