Fix bug in liveness analyzer

This commit is contained in:
Alexey Andreev 2015-03-30 18:14:48 +04:00
parent 98247b9927
commit df8a3b8206

View File

@ -15,6 +15,8 @@
*/ */
package org.teavm.model.util; package org.teavm.model.util;
import com.carrotsearch.hppc.IntOpenHashSet;
import com.carrotsearch.hppc.IntSet;
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.BitSet; import java.util.BitSet;
import java.util.Deque; import java.util.Deque;
@ -51,15 +53,19 @@ public class LivenessAnalyzer {
BasicBlock block = program.basicBlockAt(i); BasicBlock block = program.basicBlockAt(i);
for (Instruction insn : block.getInstructions()) { for (Instruction insn : block.getInstructions()) {
insn.acceptVisitor(usageExtractor); insn.acceptVisitor(usageExtractor);
IntSet usedVars = new IntOpenHashSet();
for (Variable var : usageExtractor.getUsedVariables()) { for (Variable var : usageExtractor.getUsedVariables()) {
Task task = new Task(); Task task = new Task();
task.block = i; task.block = i;
task.var = var.getIndex(); task.var = var.getIndex();
stack.push(task); stack.push(task);
usedVars.add(var.getIndex());
} }
insn.acceptVisitor(defExtractor); insn.acceptVisitor(defExtractor);
for (Variable var : defExtractor.getDefinedVariables()) { for (Variable var : defExtractor.getDefinedVariables()) {
definitions[var.getIndex()] = i; if (!usedVars.contains(var.getIndex())) {
definitions[var.getIndex()] = i;
}
} }
} }
for (TryCatchBlock tryCatch : block.getTryCatchBlocks()) { for (TryCatchBlock tryCatch : block.getTryCatchBlocks()) {