-
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into non-indy-jit
Conflicts: core/src/main/java/org/jruby/ir/IRScope.java
- 9.4.12.0
- 9.4.11.0
- 9.4.10.0
- 9.4.9.0
- 9.4.8.0
- 9.4.7.0
- 9.4.6.0
- 9.4.5.0
- 9.4.4.0
- 9.4.3.0
- 9.4.2.0
- 9.4.1.0
- 9.4.0.0
- 9.3.15.0
- 9.3.14.0
- 9.3.13.0
- 9.3.12.0
- 9.3.11.0
- 9.3.10.0
- 9.3.9.0
- 9.3.8.0
- 9.3.7.0
- 9.3.6.0
- 9.3.5.0
- 9.3.4.0
- 9.3.3.0
- 9.3.2.0
- 9.3.1.0
- 9.3.0.0
- 9.2.21.0
- 9.2.20.1
- 9.2.20.0
- 9.2.19.0
- 9.2.18.0
- 9.2.17.0
- 9.2.16.0
- 9.2.15.0
- 9.2.14.0
- 9.2.13.0
- 9.2.12.0
- 9.2.11.1
- 9.2.11.0
- 9.2.10.0
- 9.2.9.0
- 9.2.8.0
- 9.2.7.0
- 9.2.6.0
- 9.2.5.0
- 9.2.4.1
- 9.2.4.0
- 9.2.3.0
- 9.2.2.0
- 9.2.1.0
- 9.2.0.0
- 9.1.17.0
- 9.1.16.0
- 9.1.15.0
- 9.1.14.0
- 9.1.13.0
- 9.1.12.0
- 9.1.11.0
- 9.1.10.0
- 9.1.9.0
- 9.1.8.0
- 9.1.7.0
- 9.1.6.0
- 9.1.5.0
- 9.1.4.0
- 9.1.3.0
- 9.1.2.0
- 9.1.1.0
- 9.1.0.0
- 9.0.5.0
- 9.0.4.0
- 9.0.3.0
- 9.0.1.0
- 9.0.0.0
- 9.0.0.0.rc2
- 9.0.0.0.rc1
- 9.0.0.0.pre2
- 9.0.0.0.pre1
Showing
16 changed files
with
253 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
core/src/main/java/org/jruby/ir/passes/OptimizeDynScopesPass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package org.jruby.ir.passes; | ||
|
||
import org.jruby.ir.IRScope; | ||
import org.jruby.ir.IRFlags; | ||
import org.jruby.ir.instructions.Instr; | ||
import org.jruby.ir.instructions.ResultInstr; | ||
import org.jruby.ir.instructions.LoadLocalVarInstr; | ||
import org.jruby.ir.instructions.StoreLocalVarInstr; | ||
import org.jruby.ir.operands.LocalVariable; | ||
import org.jruby.ir.operands.Operand; | ||
import org.jruby.ir.operands.Variable; | ||
import org.jruby.ir.representations.BasicBlock; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.ListIterator; | ||
|
||
public class OptimizeDynScopesPass extends CompilerPass { | ||
@Override | ||
public String getLabel() { | ||
return "Optimize Dynamic Scopes"; | ||
} | ||
|
||
private void setupLocalVarReplacement(LocalVariable v, IRScope s, Map<Operand, Operand> varRenameMap) { | ||
if (varRenameMap.get(v) == null) varRenameMap.put(v, s.getNewTemporaryVariableFor(v)); | ||
} | ||
|
||
private void decrementScopeDepth(LocalVariable v, IRScope s, Map<Operand, Operand> varRenameMap) { | ||
if (varRenameMap.get(v) == null) varRenameMap.put(v, v.cloneForDepth(v.getScopeDepth()-1)); | ||
} | ||
|
||
public void eliminateLocalVars(IRScope s) { | ||
Map<Operand, Operand> varRenameMap = new HashMap<Operand, Operand>(); | ||
// Record the fact that we eliminated the scope | ||
s.getFlags().add(IRFlags.DYNSCOPE_ELIMINATED); | ||
|
||
// Since the scope does not require a binding, no need to do | ||
// any analysis. It is sufficient to rename all local var uses | ||
// with a temporary variable. | ||
boolean parentScopeNeeded = false; | ||
for (BasicBlock b: s.getCFG().getBasicBlocks()) { | ||
ListIterator<Instr> instrs = b.getInstrs().listIterator(); | ||
while (instrs.hasNext()) { | ||
Instr i = instrs.next(); | ||
if (i instanceof ResultInstr) { | ||
Variable v = ((ResultInstr) i).getResult(); | ||
// %self is local to every scope and never crosses scope boundaries and need not be spilled/refilled | ||
if (v instanceof LocalVariable && !v.isSelf()) { | ||
LocalVariable lv = (LocalVariable)v; | ||
if (lv.getScopeDepth() == 0) { | ||
// Make sure there is a replacement tmp-var allocated for lv | ||
setupLocalVarReplacement(lv, s, varRenameMap); | ||
} else { | ||
parentScopeNeeded = true; | ||
decrementScopeDepth(lv, s, varRenameMap); | ||
} | ||
} | ||
} | ||
|
||
for (Variable v : i.getUsedVariables()) { | ||
if (v instanceof LocalVariable && !v.isSelf()) { | ||
LocalVariable lv = (LocalVariable)v; | ||
if (lv.getScopeDepth() == 0) { | ||
// SSS FIXME: Ugly/Dirty! Some abstraction is broken. | ||
// If we hit a load/store instr for a local-var and we | ||
// eliminated the dynscope for it, we no longer need the | ||
// load/store instr for it. | ||
if (i instanceof LoadLocalVarInstr) { | ||
LoadLocalVarInstr llvi = (LoadLocalVarInstr)i; | ||
if (llvi.getLocalVar() == lv) { | ||
instrs.remove(); | ||
} | ||
} else if (i instanceof StoreLocalVarInstr) { | ||
StoreLocalVarInstr slvi = (StoreLocalVarInstr)i; | ||
if (slvi.getLocalVar() == lv) { | ||
instrs.remove(); | ||
} | ||
} | ||
|
||
// Make sure there is a replacement tmp-var allocated for lv | ||
setupLocalVarReplacement(lv, s, varRenameMap); | ||
} else { | ||
// SSS FIXME: Ugly/Dirty! Some abstraction is broken. | ||
if (i instanceof LoadLocalVarInstr) { | ||
LoadLocalVarInstr llvi = (LoadLocalVarInstr)i; | ||
if (llvi.getLocalVar() == lv) { | ||
llvi.decrementLVarScopeDepth(); | ||
} | ||
} else if (i instanceof StoreLocalVarInstr) { | ||
StoreLocalVarInstr slvi = (StoreLocalVarInstr)i; | ||
if (slvi.getLocalVar() == lv) { | ||
slvi.decrementLVarScopeDepth(); | ||
} | ||
} | ||
|
||
parentScopeNeeded = true; | ||
decrementScopeDepth(lv, s, varRenameMap); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (parentScopeNeeded) { | ||
s.getFlags().add(IRFlags.REUSE_PARENT_DYNSCOPE); | ||
} | ||
|
||
// Rename all local var uses with their tmp-var stand-ins | ||
for (BasicBlock b: s.getCFG().getBasicBlocks()) { | ||
for (Instr i: b.getInstrs()) i.renameVars(varRenameMap); | ||
} | ||
} | ||
|
||
@Override | ||
public Object execute(IRScope scope, Object... data) { | ||
// Make sure flags are computed | ||
scope.computeScopeFlags(); | ||
|
||
// Cannot run this on scopes that require dynamic scopes | ||
if (scope.getFlags().contains(IRFlags.REQUIRES_DYNSCOPE)) { | ||
return null; | ||
} | ||
|
||
eliminateLocalVars(scope); | ||
return null; | ||
} | ||
|
||
@Override | ||
public void invalidate(IRScope scope) { | ||
// No invalidation for this right now. | ||
// But, if necessary, we can reverse this operation. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters