From 89f835540b2ee466b1326528d3c50e0734d21ad1 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Wed, 15 Feb 2017 22:16:14 +0300 Subject: [PATCH] Add unused variable elimination to standard optimization levels --- .../optimization/VariableEscapeAnalyzer.java | 108 +----------------- core/src/main/java/org/teavm/vm/TeaVM.java | 1 + 2 files changed, 3 insertions(+), 106 deletions(-) diff --git a/core/src/main/java/org/teavm/model/optimization/VariableEscapeAnalyzer.java b/core/src/main/java/org/teavm/model/optimization/VariableEscapeAnalyzer.java index bd912112c..2a085925b 100644 --- a/core/src/main/java/org/teavm/model/optimization/VariableEscapeAnalyzer.java +++ b/core/src/main/java/org/teavm/model/optimization/VariableEscapeAnalyzer.java @@ -34,69 +34,13 @@ public final class VariableEscapeAnalyzer { return escaping; } - private static class InstructionAnalyzer implements InstructionVisitor { + private static class InstructionAnalyzer extends AbstractInstructionVisitor { private boolean[] escaping; - public InstructionAnalyzer(boolean[] escaping) { + InstructionAnalyzer(boolean[] escaping) { this.escaping = escaping; } - @Override - public void visit(EmptyInstruction insn) { - } - - @Override - public void visit(ClassConstantInstruction insn) { - } - - @Override - public void visit(NullConstantInstruction insn) { - } - - @Override - public void visit(IntegerConstantInstruction insn) { - } - - @Override - public void visit(LongConstantInstruction insn) { - } - - @Override - public void visit(FloatConstantInstruction insn) { - } - - @Override - public void visit(DoubleConstantInstruction insn) { - } - - @Override - public void visit(StringConstantInstruction insn) { - } - - @Override - public void visit(BinaryInstruction insn) { - } - - @Override - public void visit(NegateInstruction insn) { - } - - @Override - public void visit(AssignInstruction insn) { - } - - @Override - public void visit(CastInstruction insn) { - } - - @Override - public void visit(CastNumberInstruction insn) { - } - - @Override - public void visit(CastIntegerInstruction insn) { - } - @Override public void visit(BranchingInstruction insn) { escaping[insn.getOperand().getIndex()] = true; @@ -108,10 +52,6 @@ public final class VariableEscapeAnalyzer { escaping[insn.getSecondOperand().getIndex()] = true; } - @Override - public void visit(JumpInstruction insn) { - } - @Override public void visit(SwitchInstruction insn) { escaping[insn.getCondition().getIndex()] = true; @@ -129,22 +69,6 @@ public final class VariableEscapeAnalyzer { escaping[insn.getException().getIndex()] = true; } - @Override - public void visit(ConstructArrayInstruction insn) { - } - - @Override - public void visit(ConstructInstruction insn) { - } - - @Override - public void visit(ConstructMultiArrayInstruction insn) { - } - - @Override - public void visit(GetFieldInstruction insn) { - } - @Override public void visit(PutFieldInstruction insn) { if (insn.getInstance() != null) { @@ -153,22 +77,6 @@ public final class VariableEscapeAnalyzer { escaping[insn.getValue().getIndex()] = true; } - @Override - public void visit(ArrayLengthInstruction insn) { - } - - @Override - public void visit(CloneArrayInstruction insn) { - } - - @Override - public void visit(UnwrapArrayInstruction insn) { - } - - @Override - public void visit(GetElementInstruction insn) { - } - @Override public void visit(PutElementInstruction insn) { escaping[insn.getArray().getIndex()] = true; @@ -196,18 +104,6 @@ public final class VariableEscapeAnalyzer { } } - @Override - public void visit(IsInstanceInstruction insn) { - } - - @Override - public void visit(InitClassInstruction insn) { - } - - @Override - public void visit(NullCheckInstruction insn) { - } - @Override public void visit(MonitorEnterInstruction insn) { escaping[insn.getObjectRef().getIndex()] = true; diff --git a/core/src/main/java/org/teavm/vm/TeaVM.java b/core/src/main/java/org/teavm/vm/TeaVM.java index 6e5e1d3e6..72330e8b8 100644 --- a/core/src/main/java/org/teavm/vm/TeaVM.java +++ b/core/src/main/java/org/teavm/vm/TeaVM.java @@ -564,6 +564,7 @@ public class TeaVM implements TeaVMHost, ServiceRepository { } optimizations.add(new ClassInitElimination()); optimizations.add(new UnreachableBasicBlockElimination()); + optimizations.add(new UnusedVariableElimination()); return optimizations; }