Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: b3dacaac5e6d
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2a9e7a8ddeeb
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Jan 9, 2015

  1. Copy the full SHA
    aa5f27c View commit details
  2. Now with new block handling instruction this logic for preserving an …

    …instr if its
    
    result is %block is no longer neccesary since 1) there is no %block anymore 2) since
    blocks are not temp vars regular DCE will handle liveness.
    enebo committed Jan 9, 2015
    Copy the full SHA
    2a9e7a8 View commit details
7 changes: 1 addition & 6 deletions core/src/main/java/org/jruby/ir/IRScope.java
Original file line number Diff line number Diff line change
@@ -257,10 +257,6 @@ public void removeClosure(IRClosure closure) {
nestedClosures.remove(closure);
}

public Instr getLastInstr() {
return instrList.get(instrList.size() - 1);
}

public void addInstrAtBeginning(Instr instr) {
instr.computeScopeFlags(this);

@@ -284,8 +280,7 @@ public LocalVariable getNewFlipStateVariable() {
}

public void initFlipStateVariable(Variable v, Operand initState) {
// Add it to the beginning
instrList.add(0, new CopyInstr(v, initState));
addInstrAtBeginning(new CopyInstr(v, initState));
}

public Label getNewLabel(String prefix) {
17 changes: 10 additions & 7 deletions core/src/main/java/org/jruby/ir/instructions/Instr.java
Original file line number Diff line number Diff line change
@@ -94,17 +94,19 @@ public boolean computeScopeFlags(IRScope scope) {
return false;
}

/**
* Can this instruction be deleted? LVA will preserve instructions based on whether operands (variables)
* are living but even if there are no living variables then the instruction itself may not be able to be removed
* during DCE for other reasons (like if it unconditionally has a side-effect or it happens to be living in a
* scope where a binding can escape and one of its operands is a local variable).
*/
public boolean canBeDeleted(IRScope s) {
if (hasSideEffects() || operation.isDebugOp() || canRaiseException() || transfersControl()) return false;

if (this instanceof ResultInstr) {
Variable r = ((ResultInstr) this).getResult();

// %block must stay if this scope or nested scope has an eval which might yield. Safe, but conservative.
if (r.isBlock()) return !s.usesEval();

// If scope's binding escaped, then preserve lvars since consumers of the escaped binding may access those
// lvars. Safe, but extremely conservative.
// An escaped binding needs to preserve lvars since that consumers of that binding may access lvars.
if (s.bindingHasEscaped()) return !(r instanceof LocalVariable);
}

@@ -126,7 +128,7 @@ public boolean isDead() {

/* List of all variables used by all operands of this instruction */
public List<Variable> getUsedVariables() {
ArrayList<Variable> vars = new ArrayList<Variable>();
ArrayList<Variable> vars = new ArrayList<>();
for (Operand o : getOperands()) {
o.addUsedVariables(vars);
}
@@ -177,8 +179,9 @@ public void simplifyOperands(Map<Operand, Operand> valueMap, boolean force) {
* It is not required that it do so -- code correctness is not compromised by failure
* to simplify.
*
* @param scope where this instr exists
* @param valueMap Mapping from operands to their simplified values
* @returns simplified result / output of this instruction
* @return simplified result / output of this instruction
*/
public Operand simplifyAndGetResult(IRScope scope, Map<Operand, Operand> valueMap) {
simplifyOperands(valueMap, false);
9 changes: 0 additions & 9 deletions core/src/main/java/org/jruby/ir/operands/Variable.java
Original file line number Diff line number Diff line change
@@ -7,10 +7,6 @@
import java.util.Map;

public abstract class Variable extends Operand implements Comparable {
public final static String BLOCK = "%block";
public final static String CURRENT_SCOPE = "%current_scope";
public final static String CURRENT_MODULE = "%current_module";

public Variable(OperandType type) {
super(type);
}
@@ -29,11 +25,6 @@ public Operand getSimplifiedOperand(Map<Operand, Operand> valueMap, boolean forc
return (v != null) && (force || v.canCopyPropagate()) ? v : this;
}

// FIXME: Consider specialized type for special %block like for %self
public boolean isBlock() {
return BLOCK.equals(getName());
}

public boolean isSelf() {
return false;
}