Skip to content

Commit

Permalink
Enable OptimizeTempVarsPass again
Browse files Browse the repository at this point in the history
* Fix use of the incorrect instruction list
  • Loading branch information
subbuss committed Mar 3, 2015
1 parent 8c13270 commit 8e1e2f8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ir/IRScope.java
Expand Up @@ -476,7 +476,7 @@ protected void prepareFullBuildCommon() {
// This is a complicating pseudo-pass which needs to be run before CFG is generated. This
// neccesitates us needing a clonedInstrs field on IRScope. If we can rewrite this to a full
// CFG using pass we can eliminate this intermediate save and field.
//getManager().optimizeTemporaryVariablesIfEnabled(this);
getManager().optimizeTemporaryVariablesIfEnabled(this);

for (IRClosure cl: getClosures()) {
if (cl.fullInterpreterContext == null) cl.fullInterpreterContext = new FullInterpreterContext(cl, cl.getClonedInstrs());
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/java/org/jruby/ir/passes/OptimizeTempVarsPass.java
Expand Up @@ -48,10 +48,12 @@ private static void freeVar(TemporaryVariable newVar, List<TemporaryVariable> fr
}

private static void optimizeTmpVars(IRScope s) {
List<Instr> instructions = new ArrayList<>(Arrays.asList(s.getClonedInstrs()));

// Pass 1: Analyze instructions and find use and def count of temporary variables
Map<TemporaryVariable, Instr> tmpVarUses = new HashMap<>();
Map<TemporaryVariable, Instr> tmpVarDefs = new HashMap<>();
for (Instr i: s.getInterpreterContext().getInstructions()) {
for (Instr i: instructions) {
for (Variable v: i.getUsedVariables()) {
if (v instanceof TemporaryVariable) {
TemporaryVariable tv = (TemporaryVariable)v;
Expand Down Expand Up @@ -81,8 +83,6 @@ private static void optimizeTmpVars(IRScope s) {
// * If the result of this instr. has not been used, mark it dead
// * Find copies where constant values are set


List<Instr> instructions = new ArrayList<>(Arrays.asList(s.getClonedInstrs()));
ListIterator<Instr> instrs = instructions.listIterator();
while (instrs.hasNext()) {
Instr i = instrs.next();
Expand Down Expand Up @@ -214,7 +214,7 @@ else if (i instanceof CopyInstr) {
// At the first definition, we allocate a variable which then starts the live range
Map<TemporaryVariable, Integer> lastVarUseOrDef = new HashMap<TemporaryVariable, Integer>();
int iCount = -1;
for (Instr i: s.getInterpreterContext().getInstructions()) {
for (Instr i: instructions) {
iCount++;

// update last use/def
Expand Down Expand Up @@ -247,7 +247,7 @@ else if (i instanceof CopyInstr) {
iCount = -1;
s.resetTemporaryVariables();

for (Instr i: s.getInterpreterContext().getInstructions()) {
for (Instr i: instructions) {
iCount++;

// Assign new vars
Expand Down

0 comments on commit 8e1e2f8

Please sign in to comment.