Skip to content

Commit

Permalink
[IR] Renamed several classes to more accurate reflect functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
subbuss committed Mar 27, 2012
1 parent 6db14a4 commit 327418d
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public static void main(String[] args) {
long t7 = new Date().getTime();
scope.runCompilerPass(new DeadCodeElimination());
long t8 = new Date().getTime();
// scope.runCompilerPass(new AddBindingInstructions());
// scope.runCompilerPass(new AddLocalVarLoadStoreInstructions());
// long t9 = new Date().getTime();
if (isDebug) {
scope.runCompilerPass(new IRPrinter());
Expand Down
4 changes: 2 additions & 2 deletions src/org/jruby/ir/IRScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.jruby.ir.passes.IRPrinter;
import org.jruby.ir.passes.InlineTest;
import org.jruby.ir.passes.LinearizeCFG;
import org.jruby.ir.passes.AddBindingInstructions;
import org.jruby.ir.passes.AddLocalVarLoadStoreInstructions;
import org.jruby.ir.passes.LiveVariableAnalysis;
import org.jruby.ir.passes.opts.DeadCodeElimination;
import org.jruby.ir.passes.opts.LocalOptimizationPass;
Expand Down Expand Up @@ -579,7 +579,7 @@ private void runCompilerPasses() {
printPass("After inline");
}

if (RubyInstanceConfig.IR_OPT_LVAR_ACCESS) runCompilerPass(new AddBindingInstructions());
if (RubyInstanceConfig.IR_OPT_LVAR_ACCESS) runCompilerPass(new AddLocalVarLoadStoreInstructions());

// Do not run dead-code-elimination on eval-scripts because they might
// update their enclosing environments.
Expand Down
8 changes: 4 additions & 4 deletions src/org/jruby/ir/dataflow/DataFlowConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
import java.util.List;

import org.jruby.ir.dataflow.analyses.LiveVariablesProblem;
import org.jruby.ir.dataflow.analyses.BindingLoadPlacementProblem;
import org.jruby.ir.dataflow.analyses.BindingStorePlacementProblem;
import org.jruby.ir.dataflow.analyses.LoadLocalVarPlacementProblem;
import org.jruby.ir.dataflow.analyses.StoreLocalVarPlacementProblem;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.Variable;
import org.jruby.ir.transformations.inlining.InlinerInfo;

public class DataFlowConstants {
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();
public static final String LLVP_NAME = (new LoadLocalVarPlacementProblem()).getName();
public static final String SLVP_NAME = (new StoreLocalVarPlacementProblem()).getName();

/* Lattice TOP, BOTTOM, ANY values -- these will be used during dataflow analyses */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.jruby.ir.dataflow.FlowGraphNode;
import org.jruby.ir.instructions.CallBase;
import org.jruby.ir.instructions.Instr;
import org.jruby.ir.instructions.LoadFromBindingInstr;
import org.jruby.ir.instructions.LoadLocalVarInstr;
import org.jruby.ir.instructions.ResultInstr;
import org.jruby.ir.operands.ClosureLocalVariable;
import org.jruby.ir.operands.LocalVariable;
Expand All @@ -22,8 +22,8 @@
import org.jruby.ir.operands.WrappedIRClosure;
import org.jruby.ir.representations.BasicBlock;

public class BindingLoadPlacementNode extends FlowGraphNode {
public BindingLoadPlacementNode(DataFlowProblem prob, BasicBlock n) {
public class LoadLocalVarPlacementNode extends FlowGraphNode {
public LoadLocalVarPlacementNode(DataFlowProblem prob, BasicBlock n) {
super(prob, n);
}

Expand All @@ -40,12 +40,12 @@ public void buildDataFlowVars(Instr i) {

public void initSolnForNode() {
if (basicBlock == problem.getScope().cfg().getExitBB()) {
inRequiredLoads = ((BindingLoadPlacementProblem) problem).getLoadsOnScopeExit();
inRequiredLoads = ((LoadLocalVarPlacementProblem) problem).getLoadsOnScopeExit();
}
}

public void compute_MEET(BasicBlock source, FlowGraphNode pred) {
BindingLoadPlacementNode n = (BindingLoadPlacementNode) pred;
LoadLocalVarPlacementNode n = (LoadLocalVarPlacementNode) pred;
inRequiredLoads.addAll(n.outRequiredLoads);
}

Expand Down Expand Up @@ -127,7 +127,7 @@ private TemporaryVariable getLocalVarReplacement(LocalVariable v, IRScope scope,
}

public void addLoads(Map<Operand, Operand> varRenameMap) {
BindingLoadPlacementProblem blp = (BindingLoadPlacementProblem) problem;
LoadLocalVarPlacementProblem blp = (LoadLocalVarPlacementProblem) problem;
IRScope s = blp.getScope();
List<Instr> instrs = basicBlock.getInstrs();
ListIterator<Instr> it = instrs.listIterator(instrs.size());
Expand All @@ -152,7 +152,7 @@ public void addLoads(Map<Operand, Operand> varRenameMap) {
it.next();
for (LocalVariable v : reqdLoads) {
if (cl.definesLocalVariable(v)) {
it.add(new LoadFromBindingInstr(s, getLocalVarReplacement(v, s, varRenameMap), v));
it.add(new LoadLocalVarInstr(s, getLocalVarReplacement(v, s, varRenameMap), v));
it.previous();
newReqdLoads.remove(v);
}
Expand All @@ -165,7 +165,7 @@ public void addLoads(Map<Operand, Operand> varRenameMap) {
if (call.targetRequiresCallersBinding()) {
it.next();
for (LocalVariable v : reqdLoads) {
it.add(new LoadFromBindingInstr(s, getLocalVarReplacement(v, s, varRenameMap), v));
it.add(new LoadLocalVarInstr(s, getLocalVarReplacement(v, s, varRenameMap), v));
it.previous();
}
it.previous();
Expand Down Expand Up @@ -197,10 +197,10 @@ public void addLoads(Map<Operand, Operand> varRenameMap) {
IRClosure definingScope = ((ClosureLocalVariable)v).definingScope;

if ((s != definingScope) && s.isNestedInClosure(definingScope)) {
it.add(new LoadFromBindingInstr(s, getLocalVarReplacement(v, s, varRenameMap), v));
it.add(new LoadLocalVarInstr(s, getLocalVarReplacement(v, s, varRenameMap), v));
}
} else {
it.add(new LoadFromBindingInstr(s, getLocalVarReplacement(v, s, varRenameMap), v));
it.add(new LoadLocalVarInstr(s, getLocalVarReplacement(v, s, varRenameMap), v));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import java.util.Map;
import java.util.Set;

public class BindingLoadPlacementProblem extends DataFlowProblem {
public BindingLoadPlacementProblem() {
public class LoadLocalVarPlacementProblem extends DataFlowProblem {
public LoadLocalVarPlacementProblem() {
super(DataFlowProblem.DF_Direction.BACKWARD);
initLoadsOnExit = new java.util.HashSet<LocalVariable>();
bindingHasEscaped = false;
Expand All @@ -21,7 +21,7 @@ public String getName() {
}

public FlowGraphNode buildFlowGraphNode(BasicBlock bb) {
return new BindingLoadPlacementNode(this, bb);
return new LoadLocalVarPlacementNode(this, bb);
}

@Override
Expand All @@ -47,7 +47,7 @@ public void setBindingHasEscaped(boolean flag) {

public void addLoads(Map<Operand, Operand> varRenameMap) {
for (FlowGraphNode n: flowGraphNodes) {
BindingLoadPlacementNode blpn = (BindingLoadPlacementNode)n;
LoadLocalVarPlacementNode blpn = (LoadLocalVarPlacementNode)n;
blpn.addLoads(varRenameMap);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.jruby.ir.instructions.ClosureReturnInstr;
import org.jruby.ir.instructions.Instr;
import org.jruby.ir.instructions.ResultInstr;
import org.jruby.ir.instructions.StoreToBindingInstr;
import org.jruby.ir.instructions.StoreLocalVarInstr;
import org.jruby.ir.operands.ClosureLocalVariable;
import org.jruby.ir.operands.LocalVariable;
import org.jruby.ir.operands.Operand;
Expand All @@ -25,8 +25,8 @@
import org.jruby.ir.operands.WrappedIRClosure;
import org.jruby.ir.representations.BasicBlock;

public class BindingStorePlacementNode extends FlowGraphNode {
public BindingStorePlacementNode(DataFlowProblem prob, BasicBlock n) {
public class StoreLocalVarPlacementNode extends FlowGraphNode {
public StoreLocalVarPlacementNode(DataFlowProblem prob, BasicBlock n) {
super(prob, n);
}

Expand Down Expand Up @@ -54,7 +54,7 @@ public void initSolnForNode() {
}

public void compute_MEET(BasicBlock source, FlowGraphNode pred) {
BindingStorePlacementNode n = (BindingStorePlacementNode) pred;
StoreLocalVarPlacementNode n = (StoreLocalVarPlacementNode) pred;
inDirtyVars.addAll(n.outDirtyVars);

// For binding allocation, we are using the and operator -- so only if the binding has been allocated
Expand Down Expand Up @@ -136,23 +136,23 @@ private TemporaryVariable getLocalVarReplacement(LocalVariable v, IRScope scope,
return value;
}

private void addClosureExitBindingStores(IRScope scope, ListIterator<Instr> instrs, Set<LocalVariable> dirtyVars, Map<Operand, Operand> varRenameMap) {
private void addClosureExitStoreLocalVars(IRScope scope, ListIterator<Instr> instrs, Set<LocalVariable> dirtyVars, Map<Operand, Operand> varRenameMap) {
for (LocalVariable v : dirtyVars) {
if (v instanceof ClosureLocalVariable) {
IRClosure definingScope = ((ClosureLocalVariable)v).definingScope;
if ((scope != definingScope) && scope.isNestedInClosure(definingScope)) {
instrs.add(new StoreToBindingInstr(getLocalVarReplacement(v, scope, varRenameMap), scope, v));
instrs.add(new StoreLocalVarInstr(getLocalVarReplacement(v, scope, varRenameMap), scope, v));
}
} else {
instrs.add(new StoreToBindingInstr(getLocalVarReplacement(v, scope, varRenameMap), scope, v));
instrs.add(new StoreLocalVarInstr(getLocalVarReplacement(v, scope, varRenameMap), scope, v));
}
}
}

public void addStoreAndBindingAllocInstructions(Map<Operand, Operand> varRenameMap, Set<LocalVariable> callsiteDirtyVars) {
boolean addAllocateBindingInstructions = false; // SSS: This is going to be useful during JIT -- we are far away from there at this time

BindingStorePlacementProblem bsp = (BindingStorePlacementProblem) problem;
StoreLocalVarPlacementProblem bsp = (StoreLocalVarPlacementProblem) problem;
IRScope scope = bsp.getScope();
ListIterator<Instr> instrs = basicBlock.getInstrs().listIterator();
Set<LocalVariable> dirtyVars = new HashSet<LocalVariable>(inDirtyVars);
Expand Down Expand Up @@ -207,7 +207,7 @@ public void addStoreAndBindingAllocInstructions(Map<Operand, Operand> varRenameM
Set<LocalVariable> newDirtyVars = new HashSet<LocalVariable>(dirtyVars);
for (LocalVariable v : dirtyVars) {
if (spillAllVars || cl.usesLocalVariable(v)) {
instrs.add(new StoreToBindingInstr(getLocalVarReplacement(v, scope, varRenameMap), scope, v));
instrs.add(new StoreLocalVarInstr(getLocalVarReplacement(v, scope, varRenameMap), scope, v));
newDirtyVars.remove(v);
} else if (cl.definesLocalVariable(v)) {
// These variables will be spilt inside the closure -- so they will no longer be dirty after the call site!
Expand All @@ -225,7 +225,7 @@ public void addStoreAndBindingAllocInstructions(Map<Operand, Operand> varRenameM
}
}
for (LocalVariable v : dirtyVars) {
instrs.add(new StoreToBindingInstr(getLocalVarReplacement(v, scope, varRenameMap), scope, v));
instrs.add(new StoreLocalVarInstr(getLocalVarReplacement(v, scope, varRenameMap), scope, v));
}
instrs.next();
dirtyVars.clear();
Expand Down Expand Up @@ -266,7 +266,7 @@ public void addStoreAndBindingAllocInstructions(Map<Operand, Operand> varRenameM
}

instrs.previous();
addClosureExitBindingStores(scope, instrs, dirtyVars, varRenameMap);
addClosureExitStoreLocalVars(scope, instrs, dirtyVars, varRenameMap);
instrs.next();

// Nothing is dirty anymore -- everything that needs spilling has been spilt
Expand All @@ -288,7 +288,7 @@ public void addStoreAndBindingAllocInstructions(Map<Operand, Operand> varRenameM
}

// If this is the exit BB, add binding stores for all vars that are still dirty
if (amExitBB) addClosureExitBindingStores(scope, instrs, dirtyVars, varRenameMap);
if (amExitBB) addClosureExitStoreLocalVars(scope, instrs, dirtyVars, varRenameMap);
}

Set<LocalVariable> inDirtyVars; // On entry to flow graph node: Variables that need to be stored to the heap binding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.jruby.ir.dataflow.DataFlowProblem;
import org.jruby.ir.dataflow.FlowGraphNode;
import org.jruby.ir.instructions.ReceiveExceptionInstr;
import org.jruby.ir.instructions.StoreToBindingInstr;
import org.jruby.ir.instructions.StoreLocalVarInstr;
import org.jruby.ir.instructions.ThrowExceptionInstr;
import org.jruby.ir.operands.Label;
import org.jruby.ir.operands.LocalVariable;
Expand All @@ -26,9 +26,9 @@
// strictly speaking, this is a AND of two independent dataflow analyses -- we are doing these together for
// efficiency reasons, and also because the binding allocation problem is also a forwards flow problem and is a
// relatively straightforward analysis.
public class BindingStorePlacementProblem extends DataFlowProblem {
public class StoreLocalVarPlacementProblem extends DataFlowProblem {

public BindingStorePlacementProblem() {
public StoreLocalVarPlacementProblem() {
super(DataFlowProblem.DF_Direction.FORWARD);
}

Expand All @@ -37,7 +37,7 @@ public String getName() {
}

public FlowGraphNode buildFlowGraphNode(BasicBlock bb) {
return new BindingStorePlacementNode(this, bb);
return new StoreLocalVarPlacementNode(this, bb);
}

@Override
Expand Down Expand Up @@ -65,7 +65,7 @@ public void addStoreAndBindingAllocInstructions(Map<Operand, Operand> varRenameM
}

for (FlowGraphNode n : flowGraphNodes) {
BindingStorePlacementNode bspn = (BindingStorePlacementNode) n;
StoreLocalVarPlacementNode bspn = (StoreLocalVarPlacementNode) n;
if (mightRequireGlobalEnsureBlock && !cfg.bbIsProtected(bspn.getBB())) {
bspn.addStoreAndBindingAllocInstructions(varRenameMap, dirtyVars);
} else {
Expand All @@ -83,7 +83,7 @@ public void addStoreAndBindingAllocInstructions(Map<Operand, Operand> varRenameM
value = cfgScope.getNewTemporaryVariable("%t_" + v.getName());
varRenameMap.put(v, value);
}
geb.addInstr(new StoreToBindingInstr(value, (IRClosure) cfgScope, v));
geb.addInstr(new StoreLocalVarInstr(value, (IRClosure) cfgScope, v));
}
geb.addInstr(new ThrowExceptionInstr(exc));
cfg.addGlobalEnsureBlock(geb);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

public class LoadFromBindingInstr extends Instr implements ResultInstr {
public class LoadLocalVarInstr extends Instr implements ResultInstr {
private IRScope scope;
private TemporaryVariable result;

Expand All @@ -22,10 +22,10 @@ public class LoadFromBindingInstr extends Instr implements ResultInstr {
* its (a) name (b) offset (c) scope-depth. */
private LocalVariable lvar;

public LoadFromBindingInstr(IRScope scope, TemporaryVariable result, LocalVariable lvar) {
public LoadLocalVarInstr(IRScope scope, TemporaryVariable result, LocalVariable lvar) {
super(Operation.BINDING_LOAD);

assert result != null: "LoadFromBindingInstr result is null";
assert result != null: "LoadLocalVarInstr result is null";

this.lvar = lvar;
this.result = result;
Expand All @@ -51,7 +51,7 @@ public String toString() {
@Override
public Instr cloneForInlining(InlinerInfo ii) {
// SSS FIXME: Do we need to rename lvar really? It is just a name-proxy!
return new LoadFromBindingInstr(scope, (TemporaryVariable)ii.getRenamedVariable(result), (LocalVariable)ii.getRenamedVariable(lvar));
return new LoadLocalVarInstr(scope, (TemporaryVariable)ii.getRenamedVariable(result), (LocalVariable)ii.getRenamedVariable(lvar));
}

@Interp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

public class StoreToBindingInstr extends Instr {
public class StoreLocalVarInstr extends Instr {
private IRScope scope;
private Operand value;

Expand All @@ -21,7 +21,7 @@ public class StoreToBindingInstr extends Instr {
* its (a) name (b) offset (c) scope-depth. */
private LocalVariable lvar;

public StoreToBindingInstr(Operand value, IRScope scope, LocalVariable lvar) {
public StoreLocalVarInstr(Operand value, IRScope scope, LocalVariable lvar) {
super(Operation.BINDING_STORE);

this.lvar = lvar;
Expand All @@ -46,7 +46,7 @@ public String toString() {
@Override
public Instr cloneForInlining(InlinerInfo ii) {
// SSS FIXME: Do we need to rename lvar really? It is just a name-proxy!
return new StoreToBindingInstr(value.cloneForInlining(ii), scope, (LocalVariable)lvar.cloneForInlining(ii));
return new StoreLocalVarInstr(value.cloneForInlining(ii), scope, (LocalVariable)lvar.cloneForInlining(ii));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
import org.jruby.ir.IRClosure;
import org.jruby.ir.IRMethod;
import org.jruby.ir.IRScope;
import org.jruby.ir.dataflow.analyses.BindingLoadPlacementProblem;
import org.jruby.ir.dataflow.analyses.BindingStorePlacementProblem;
import org.jruby.ir.dataflow.analyses.LoadLocalVarPlacementProblem;
import org.jruby.ir.dataflow.analyses.StoreLocalVarPlacementProblem;
import org.jruby.ir.instructions.Instr;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.representations.BasicBlock;

public class AddBindingInstructions extends CompilerPass {
public static String[] NAMES = new String[] { "add_binding", "add_binding_instructions" };
public class AddLocalVarLoadStoreInstructions extends CompilerPass {
public static String[] NAMES = new String[] { "add_lvar_load_store", "add_local_var_load_store_instructions" };

public String getLabel() {
return "Add Binding Instructions";
return "Add Local Variable Load/Store Instructions";
}

public boolean isPreOrder() {
Expand All @@ -26,11 +26,11 @@ public boolean isPreOrder() {
public Object execute(IRScope s, Object... data) {
// if (s.requiresBinding()) {

BindingStorePlacementProblem fsp = new BindingStorePlacementProblem();
StoreLocalVarPlacementProblem fsp = new StoreLocalVarPlacementProblem();
fsp.setup(s);
fsp.compute_MOP_Solution();

BindingLoadPlacementProblem frp = new BindingLoadPlacementProblem();
LoadLocalVarPlacementProblem frp = new LoadLocalVarPlacementProblem();
frp.setup(s);
frp.compute_MOP_Solution();

Expand Down

0 comments on commit 327418d

Please sign in to comment.