Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into non-indy-jit
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Oct 10, 2014
2 parents a16dfbb + 71cddf0 commit 0bf25c8
Show file tree
Hide file tree
Showing 44 changed files with 235 additions and 192 deletions.
20 changes: 7 additions & 13 deletions core/src/main/java/org/jruby/ir/IRClosure.java
Expand Up @@ -290,20 +290,10 @@ protected IRClosure cloneForInlining(CloneInfo ii, IRClosure clone) {
SimpleCloneInfo clonedII = ii.cloneForCloningClosure(clone);

if (getCFG() != null) {
// Clone the cfg
CFG clonedCFG = new CFG(clone);
clone.setCFG(clonedCFG);
clonedCFG.cloneForCloningClosure(getCFG(), clone, clonedII);
clone.setCFG(getCFG().clone(clonedII, clone));
} else {
// Clone the instruction list
for (Instr i: getInstrs()) {
Instr clonedInstr = i.clone(clonedII);
if (clonedInstr instanceof CallBase) {
CallBase call = (CallBase)clonedInstr;
Operand block = call.getClosureArg(null);
if (block instanceof WrappedIRClosure) clone.addClosure(((WrappedIRClosure)block).getClosure());
}
clone.addInstr(clonedInstr);
clone.addInstr(i.clone(clonedII));
}
}

Expand All @@ -314,14 +304,18 @@ public IRClosure cloneForInlining(CloneInfo ii) {
IRClosure clonedClosure;
IRScope lexicalParent = ii.getScope();

if (ii instanceof SimpleCloneInfo) {
if (ii instanceof SimpleCloneInfo && !((SimpleCloneInfo)ii).isEnsureBlockCloneMode()) {
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);
}

// WrappedIRClosure should always have a single unique IRClosure in them so we should
// not end up adding n copies of the same closure as distinct clones...
lexicalParent.addClosure(clonedClosure);

return cloneForInlining(ii, clonedClosure);
}

Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/ir/IRScope.java
Expand Up @@ -761,6 +761,7 @@ public void computeScopeFlags() {
|| flags.contains(HAS_NONLOCAL_RETURNS)
|| flags.contains(CAN_RECEIVE_NONLOCAL_RETURNS)
|| flags.contains(BINDING_HAS_ESCAPED)
|| flags.contains(USES_ZSUPER)
// SSS FIXME: checkArity for keyword args
// looks up a keyword arg in the static scope
// which currently requires a dynamic scope to
Expand Down
Expand Up @@ -153,7 +153,7 @@ public Object execute(IRScope scope, Object... data) {

// FIXME: Useless for now
// Run on all nested closures.
for (IRClosure c: scope.getClosures()) execute(c);
for (IRClosure c: scope.getClosures()) run(c, false, true);

// LVA information is no longer valid after the pass
// FIXME: Grrr ... this seems broken to have to create a new object to invalidate
Expand Down
Expand Up @@ -67,7 +67,7 @@ public Object execute(IRScope s, Object... data) {
// Run on all nested closures.
//
// In the current implementation, nested scopes are processed independently (unlike Live Variable Analysis)
for (IRClosure c: s.getClosures()) execute(c);
for (IRClosure c: s.getClosures()) run(c, false, true);

// LVA information is no longer valid after this pass
// FIXME: Grrr ... this seems broken to have to create a new object to invalidate
Expand Down
10 changes: 10 additions & 0 deletions core/src/main/java/org/jruby/ir/passes/CompilerPass.java
Expand Up @@ -30,6 +30,16 @@ public abstract class CompilerPass {
*/
public abstract String getLabel();

@Override
public int hashCode() {
return getLabel().hashCode();
}

@Override
public boolean equals(Object other) {
return (other != null) && (other instanceof CompilerPass) && (getLabel() == ((CompilerPass)other).getLabel());
}

/**
* Meat of an individual pass. run will call this after dependency
* resolution.
Expand Down
Expand Up @@ -24,7 +24,7 @@ public Object execute(IRScope scope, Object... data) {
((LiveVariablesProblem) data[0]).markDeadInstructions();

for (IRClosure cl: scope.getClosures()) {
run(cl, true);
run(cl, false, true);
}

return true;
Expand Down
Expand Up @@ -53,7 +53,7 @@ private void processCFG(CFG cfg) {

// recurse
for (IRScope childScope : cfg.getScope().getClosures()) {
processCFG(childScope.cfg());
run(childScope, false, true);
}
}
}
@@ -1,7 +1,6 @@
package org.jruby.ir.passes;

import org.jruby.ir.IRClosure;
import org.jruby.ir.IREvalScript;
import org.jruby.ir.IRFlags;
import org.jruby.ir.IRScope;
import org.jruby.ir.instructions.ClosureAcceptingInstr;
Expand All @@ -15,7 +14,6 @@
import org.jruby.ir.dataflow.analyses.LiveVariablesProblem;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.List;
Expand Down
Expand Up @@ -30,7 +30,7 @@ public List<Class<? extends CompilerPass>> getDependencies() {
public Object execute(IRScope s, Object... data) {
// This let us compute execute scope flags for a method based on what all nested closures do
for (IRClosure c: s.getClosures()) {
run(c, true);
run(c, false, true);
}

for (BasicBlock b: ((CFG) data[0]).getBasicBlocks()) {
Expand Down
Expand Up @@ -18,7 +18,7 @@ public String getLabel() {
@Override
public Object execute(IRScope s, Object... data) {
for (IRClosure c: s.getClosures()) {
run(c, true);
run(c, false, true);
}

optimizeTmpVars(s);
Expand Down
35 changes: 21 additions & 14 deletions core/src/main/java/org/jruby/ir/representations/BasicBlock.java
Expand Up @@ -11,6 +11,7 @@
import org.jruby.ir.operands.Label;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.WrappedIRClosure;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.ir.transformations.inlining.InlineCloneInfo;
import org.jruby.ir.transformations.inlining.SimpleCloneInfo;
import org.jruby.ir.util.ExplicitVertexID;
Expand Down Expand Up @@ -149,6 +150,25 @@ public void swallowBB(BasicBlock foodBB) {
this.instrs.addAll(foodBB.instrs);
}

// FIXME: Untested in inliner (and we need to replace cloneInstrs(InlineCloneInfo) with this).
public BasicBlock clone(CloneInfo info, CFG newCFG) {
BasicBlock newBB = new BasicBlock(newCFG, info.getRenamedLabel(label));
boolean isClosureClone = info instanceof InlineCloneInfo && ((InlineCloneInfo) info).isClosure();

for (Instr instr: instrs) {
Instr newInstr = instr.clone(info);

if (newInstr != null) { // inliner may kill off unneeded instr
newBB.addInstr(newInstr);
if (isClosureClone && newInstr instanceof YieldInstr) {
((InlineCloneInfo) info).recordYieldSite(newBB, (YieldInstr) newInstr);
}
}
}

return newBB;
}

public void cloneInstrs(SimpleCloneInfo ii) {
if (!isEmpty()) {
List<Instr> oldInstrs = instrs;
Expand All @@ -157,11 +177,6 @@ public void cloneInstrs(SimpleCloneInfo ii) {
for (Instr i: oldInstrs) {
Instr clonedInstr = i.clone(ii);
clonedInstr.setIPC(i.getIPC());
if (clonedInstr instanceof CallBase) {
CallBase call = (CallBase)clonedInstr;
Operand block = call.getClosureArg(null);
if (block instanceof WrappedIRClosure) cfg.getScope().addClosure(((WrappedIRClosure)block).getClosure());
}
instrs.add(clonedInstr);
}
}
Expand All @@ -171,21 +186,13 @@ public void cloneInstrs(SimpleCloneInfo ii) {
}

public BasicBlock cloneForInlining(InlineCloneInfo ii) {
IRScope hostScope = ii.getHostScope();
BasicBlock clonedBB = ii.getOrCreateRenamedBB(this);

for (Instr i: getInstrs()) {
Instr clonedInstr = i.clone(ii);
if (clonedInstr != null) {
clonedBB.addInstr(clonedInstr);
if (clonedInstr instanceof YieldInstr) {
ii.recordYieldSite(clonedBB, (YieldInstr)clonedInstr);
}
if (clonedInstr instanceof CallBase) {
CallBase call = (CallBase)clonedInstr;
Operand block = call.getClosureArg(null);
if (block instanceof WrappedIRClosure) hostScope.addClosure(((WrappedIRClosure)block).getClosure());
}
if (clonedInstr instanceof YieldInstr) ii.recordYieldSite(clonedBB, (YieldInstr)clonedInstr);
}
}

Expand Down

0 comments on commit 0bf25c8

Please sign in to comment.