Skip to content

Commit

Permalink
IR: Push setup into constructor. Remove unused code (looping on closu…
Browse files Browse the repository at this point in the history
…res)
  • Loading branch information
enebo committed Mar 6, 2012
1 parent 7585f52 commit 961cb46
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 29 deletions.
@@ -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;

Expand All @@ -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);
}
}
}
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/org/jruby/compiler/ir/dataflow/DataFlowConstants.java
Expand Up @@ -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();

Expand Down
Expand Up @@ -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);
}

Expand Down Expand Up @@ -367,7 +366,7 @@ BitSet getLiveInBitSet() {
}

BitSet getLiveOutBitSet() {
return this.out;
return out;
}

private BitSet in; // Variables live at entry of this node
Expand Down
@@ -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;
Expand All @@ -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<LocalVariable> EMPTY_SET = new HashSet<LocalVariable>();

public LiveVariablesProblem(IRScope scope) {
this(scope, EMPTY_SET);
}

LiveVariablesProblem(IRScope scope, Set<LocalVariable> nonSelfLocalVars) {
super(DataFlowProblem.DF_Direction.BACKWARD);

setup(scope, nonSelfLocalVars);
}

public DataFlowVar getDFVar(Variable v) {
return dfVarMap.get(v);
}
Expand Down Expand Up @@ -88,10 +96,8 @@ public void setup(IRScope scope, Collection<LocalVariable> 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);
}
}

Expand Down Expand Up @@ -128,7 +134,7 @@ public Set<LocalVariable> getNonSelfLocalVars() {
}

public String getName() {
return "Live Variables Analysis";
return NAME;
}

/* ----------- Private Interface ------------ */
Expand Down

0 comments on commit 961cb46

Please sign in to comment.