Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Split apart InlinerInfo into SimpleCloneInfo and InlineCloneInfo. Spe…
…cialization used to make it clearer which code is performing which type of cloning
  • Loading branch information
enebo committed Oct 9, 2014
1 parent 48601fd commit 94eb4ae
Show file tree
Hide file tree
Showing 144 changed files with 840 additions and 840 deletions.
7 changes: 3 additions & 4 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Expand Up @@ -13,8 +13,7 @@
import org.jruby.ir.operands.*;
import org.jruby.ir.operands.Boolean;
import org.jruby.ir.operands.Float;
import org.jruby.ir.transformations.inlining.CloneMode;
import org.jruby.ir.transformations.inlining.InlinerInfo;
import org.jruby.ir.transformations.inlining.SimpleCloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Arity;
import org.jruby.runtime.CallType;
Expand Down Expand Up @@ -221,7 +220,7 @@ public void emitBody(IRBuilder b, IRScope s) {
}

public void cloneIntoHostScope(IRBuilder b, IRScope s) {
InlinerInfo ii = new InlinerInfo(null, s, CloneMode.ENSURE_BLOCK_CLONE);
SimpleCloneInfo ii = new SimpleCloneInfo(s, true);

// Clone required labels.
// During normal cloning below, labels not found in the rename map
Expand All @@ -237,7 +236,7 @@ public void cloneIntoHostScope(IRBuilder b, IRScope s) {
b.addInstr(s, new LabelInstr(ii.getRenamedLabel(start)));
b.addInstr(s, new ExceptionRegionStartMarkerInstr(bodyRescuer));
for (Instr i: instrs) {
Instr clonedInstr = i.cloneForInlining(ii);
Instr clonedInstr = i.clone(ii);
if (clonedInstr instanceof CallBase) {
CallBase call = (CallBase)clonedInstr;
Operand block = call.getClosureArg(null);
Expand Down
34 changes: 21 additions & 13 deletions core/src/main/java/org/jruby/ir/IRClosure.java
Expand Up @@ -4,7 +4,8 @@
import org.jruby.ir.operands.*;
import org.jruby.ir.representations.BasicBlock;
import org.jruby.ir.representations.CFG;
import org.jruby.ir.transformations.inlining.InlinerInfo;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.ir.transformations.inlining.SimpleCloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Arity;
import org.jruby.runtime.BlockBody;
Expand Down Expand Up @@ -61,10 +62,11 @@ protected IRClosure(IRManager manager, IRScope lexicalParent, String fileName, i
}

/** Used by cloning code */
protected IRClosure(IRClosure c, IRScope lexicalParent, String prefix) {
/* Inlining generates a new name and id and basic cloning will reuse the originals name */
protected IRClosure(IRClosure c, IRScope lexicalParent, int closureId, String fullName) {
super(c, lexicalParent);
this.closureId = lexicalParent.getNextClosureId();
setName(prefix + closureId);
this.closureId = closureId;
super.setName(fullName);
this.startLabel = getNewLabel(getName() + "_START");
this.endLabel = getNewLabel(getName() + "_END");
if (getManager().isDryRun()) {
Expand Down Expand Up @@ -281,12 +283,11 @@ public int getNestingDepth() {
return nestingDepth;
}

protected IRClosure cloneForInlining(InlinerInfo ii, IRClosure clone) {
protected IRClosure cloneForInlining(CloneInfo ii, IRClosure clone) {
clone.nestingDepth = this.nestingDepth;
clone.parameterList = this.parameterList;

// Create a new inliner info object
InlinerInfo clonedII = ii.cloneForCloningClosure(clone);
SimpleCloneInfo clonedII = ii.cloneForCloningClosure(clone);

if (getCFG() != null) {
// Clone the cfg
Expand All @@ -296,7 +297,7 @@ protected IRClosure cloneForInlining(InlinerInfo ii, IRClosure clone) {
} else {
// Clone the instruction list
for (Instr i: getInstrs()) {
Instr clonedInstr = i.cloneForInlining(clonedII);
Instr clonedInstr = i.clone(clonedII);
if (clonedInstr instanceof CallBase) {
CallBase call = (CallBase)clonedInstr;
Operand block = call.getClosureArg(null);
Expand All @@ -309,9 +310,17 @@ protected IRClosure cloneForInlining(InlinerInfo ii, IRClosure clone) {
return clone;
}

public IRClosure cloneForInlining(InlinerInfo ii) {
// FIXME: This is buggy! Is this not dependent on clone-mode??
IRClosure clonedClosure = new IRClosure(this, ii.getNewLexicalParentForClosure(), "_CLOSURE_CLONE_");
public IRClosure cloneForInlining(CloneInfo ii) {
IRClosure clonedClosure;
IRScope lexicalParent = ii.getScope();

if (ii instanceof SimpleCloneInfo) {
clonedClosure = new IRClosure(this, lexicalParent, closureId, getName());
} else {
int id = lexicalParent.getNextClosureId();
String fullName = lexicalParent.getName() + "_CLOSURE_CLONE_" + id;
clonedClosure = new IRClosure(this, lexicalParent, id, fullName);
}

return cloneForInlining(ii, clonedClosure);
}
Expand Down Expand Up @@ -361,8 +370,7 @@ protected boolean addGEBForUncaughtBreaks() {
@Override
public void setName(String name) {
// We can distinguish closures only with parent scope name
String fullName = getLexicalParent().getName() + name;
super.setName(fullName);
super.setName(getLexicalParent().getName() + name);
}

public Arity getArity() {
Expand Down
22 changes: 16 additions & 6 deletions core/src/main/java/org/jruby/ir/IRFor.java
@@ -1,6 +1,7 @@
package org.jruby.ir;

import org.jruby.ir.transformations.inlining.InlinerInfo;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.ir.transformations.inlining.SimpleCloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.parser.StaticScopeFactory;
import org.jruby.runtime.Arity;
Expand All @@ -18,8 +19,8 @@ public IRFor(IRManager manager, IRScope lexicalParent, int lineNumber, StaticSco
}

/** Used by cloning code */
private IRFor(IRClosure c, IRScope lexicalParent) {
super(c, lexicalParent, "_FOR_LOOP_CLONE_");
private IRFor(IRClosure c, IRScope lexicalParent, int id, String fullName) {
super(c, lexicalParent, id, fullName);
}

@Override
Expand All @@ -28,9 +29,18 @@ public IRScopeType getScopeType() {
}

@Override
public IRClosure cloneForInlining(InlinerInfo ii) {
// FIXME: This is buggy! Is this not dependent on clone-mode??
IRClosure clonedClosure = new IRFor(this, ii.getNewLexicalParentForClosure());
public IRClosure cloneForInlining(CloneInfo ii) {
IRClosure clonedClosure;
IRScope lexicalParent = ii.getScope();

if (ii instanceof SimpleCloneInfo) {
clonedClosure = new IRFor(this, lexicalParent, closureId, getName());
} else {
int id = lexicalParent.getNextClosureId();
String fullName = lexicalParent.getName() + "_FOR_LOOP_CLONE_" + id;
clonedClosure = new IRFor(this, lexicalParent, id, fullName);
}

return cloneForInlining(ii, clonedClosure);
}
}
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/instructions/AliasInstr.java
Expand Up @@ -6,7 +6,7 @@
import org.jruby.ir.Operation;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.ir.transformations.inlining.InlinerInfo;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
Expand Down Expand Up @@ -49,7 +49,7 @@ public void simplifyOperands(Map<Operand, Operand> valueMap, boolean force) {
}

@Override
public Instr cloneForInlining(InlinerInfo ii) {
public Instr clone(CloneInfo ii) {
return new AliasInstr(getNewName().cloneForInlining(ii), getOldName().cloneForInlining(ii));
}

Expand Down
Expand Up @@ -4,7 +4,7 @@
import org.jruby.ir.Operation;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.Variable;
import org.jruby.ir.transformations.inlining.InlinerInfo;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
Expand Down Expand Up @@ -35,7 +35,7 @@ public void updateResult(Variable v) {
}

@Override
public Instr cloneForInlining(InlinerInfo ii) {
public Instr clone(CloneInfo ii) {
return new ArgScopeDepthInstr(ii.getRenamedVariable(result));
}

Expand Down
Expand Up @@ -5,7 +5,7 @@
import org.jruby.ir.instructions.specialized.OneArgOperandAttrAssignInstr;
import org.jruby.ir.operands.MethAddr;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.transformations.inlining.InlinerInfo;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.*;
import org.jruby.runtime.builtin.IRubyObject;
Expand All @@ -22,7 +22,7 @@ public AttrAssignInstr(AttrAssignInstr instr) {
}

@Override
public Instr cloneForInlining(InlinerInfo ii) {
public Instr clone(CloneInfo ii) {
return new AttrAssignInstr(receiver.cloneForInlining(ii),
(MethAddr)getMethodAddr().cloneForInlining(ii), cloneCallArgs(ii));
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/instructions/BEQInstr.java
Expand Up @@ -4,7 +4,7 @@
import org.jruby.ir.Operation;
import org.jruby.ir.operands.Boolean;
import org.jruby.ir.operands.*;
import org.jruby.ir.transformations.inlining.InlinerInfo;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
Expand All @@ -25,7 +25,7 @@ protected BEQInstr(Operand v1, Operand v2, Label jmpTarget) {
}

@Override
public Instr cloneForInlining(InlinerInfo ii) {
public Instr clone(CloneInfo ii) {
return new BEQInstr(getArg1().cloneForInlining(ii), getArg2().cloneForInlining(ii), ii.getRenamedLabel(getJumpTarget()));
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/instructions/BFalseInstr.java
Expand Up @@ -4,7 +4,7 @@
import org.jruby.ir.Operation;
import org.jruby.ir.operands.Label;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.transformations.inlining.InlinerInfo;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
Expand All @@ -21,7 +21,7 @@ public BFalseInstr(Operand v, Label jmpTarget) {
}

@Override
public Instr cloneForInlining(InlinerInfo ii) {
public Instr clone(CloneInfo ii) {
return new BFalseInstr(getOperation(), getArg1().cloneForInlining(ii), ii.getRenamedLabel(getJumpTarget()));
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/instructions/BNEInstr.java
Expand Up @@ -6,7 +6,7 @@
import org.jruby.ir.operands.Label;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.UndefinedValue;
import org.jruby.ir.transformations.inlining.InlinerInfo;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
Expand All @@ -25,7 +25,7 @@ public BNEInstr(Operand v1, Operand v2, Label jmpTarget) {
}

@Override
public Instr cloneForInlining(InlinerInfo ii) {
public Instr clone(CloneInfo ii) {
return new BNEInstr(getArg1().cloneForInlining(ii),
getArg2().cloneForInlining(ii), ii.getRenamedLabel(getJumpTarget()));
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/instructions/BNilInstr.java
Expand Up @@ -4,7 +4,7 @@
import org.jruby.ir.Operation;
import org.jruby.ir.operands.Label;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.transformations.inlining.InlinerInfo;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
Expand All @@ -16,7 +16,7 @@ public BNilInstr(Operand v, Label jmpTarget) {
}

@Override
public Instr cloneForInlining(InlinerInfo ii) {
public Instr clone(CloneInfo ii) {
return new BNilInstr(getArg1().cloneForInlining(ii), ii.getRenamedLabel(getJumpTarget()));
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/instructions/BTrueInstr.java
Expand Up @@ -4,7 +4,7 @@
import org.jruby.ir.Operation;
import org.jruby.ir.operands.Label;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.transformations.inlining.InlinerInfo;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
Expand All @@ -20,7 +20,7 @@ public BTrueInstr(Operand v, Label jmpTarget) {
}

@Override
public Instr cloneForInlining(InlinerInfo ii) {
public Instr clone(CloneInfo ii) {
return new BTrueInstr(getOperation(), getArg1().cloneForInlining(ii), ii.getRenamedLabel(getJumpTarget()));
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/instructions/BUndefInstr.java
Expand Up @@ -5,7 +5,7 @@
import org.jruby.ir.operands.Label;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.UndefinedValue;
import org.jruby.ir.transformations.inlining.InlinerInfo;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
Expand All @@ -17,7 +17,7 @@ public BUndefInstr(Operand v, Label jmpTarget) {
}

@Override
public Instr cloneForInlining(InlinerInfo ii) {
public Instr clone(CloneInfo ii) {
return new BUndefInstr(getArg1().cloneForInlining(ii), ii.getRenamedLabel(getJumpTarget()));
}

Expand Down
Expand Up @@ -6,7 +6,7 @@
import org.jruby.ir.Operation;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.Variable;
import org.jruby.ir.transformations.inlining.InlinerInfo;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
Expand Down Expand Up @@ -68,7 +68,7 @@ public void simplifyOperands(Map<Operand, Operand> valueMap, boolean force) {
}

@Override
public Instr cloneForInlining(InlinerInfo ii) {
public Instr clone(CloneInfo ii) {
List<Operand> newPieces = new ArrayList<Operand>();
for (Operand p : pieces) {
newPieces.add(p.cloneForInlining(ii));
Expand Down
Expand Up @@ -5,7 +5,7 @@
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.Variable;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.ir.transformations.inlining.InlinerInfo;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
Expand Down Expand Up @@ -51,7 +51,7 @@ public void updateResult(Variable v) {
}

@Override
public Instr cloneForInlining(InlinerInfo ii) {
public Instr clone(CloneInfo ii) {
return new BlockGivenInstr(ii.getRenamedVariable(result), blockArg.cloneForInlining(ii));
}

Expand Down

0 comments on commit 94eb4ae