Add unused variable elimination to standard optimization levels

This commit is contained in:
Alexey Andreev 2017-02-15 22:16:14 +03:00
parent 6c6e7c0d4d
commit 89f835540b
2 changed files with 3 additions and 106 deletions

View File

@ -34,69 +34,13 @@ public final class VariableEscapeAnalyzer {
return escaping; return escaping;
} }
private static class InstructionAnalyzer implements InstructionVisitor { private static class InstructionAnalyzer extends AbstractInstructionVisitor {
private boolean[] escaping; private boolean[] escaping;
public InstructionAnalyzer(boolean[] escaping) { InstructionAnalyzer(boolean[] escaping) {
this.escaping = 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 @Override
public void visit(BranchingInstruction insn) { public void visit(BranchingInstruction insn) {
escaping[insn.getOperand().getIndex()] = true; escaping[insn.getOperand().getIndex()] = true;
@ -108,10 +52,6 @@ public final class VariableEscapeAnalyzer {
escaping[insn.getSecondOperand().getIndex()] = true; escaping[insn.getSecondOperand().getIndex()] = true;
} }
@Override
public void visit(JumpInstruction insn) {
}
@Override @Override
public void visit(SwitchInstruction insn) { public void visit(SwitchInstruction insn) {
escaping[insn.getCondition().getIndex()] = true; escaping[insn.getCondition().getIndex()] = true;
@ -129,22 +69,6 @@ public final class VariableEscapeAnalyzer {
escaping[insn.getException().getIndex()] = true; 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 @Override
public void visit(PutFieldInstruction insn) { public void visit(PutFieldInstruction insn) {
if (insn.getInstance() != null) { if (insn.getInstance() != null) {
@ -153,22 +77,6 @@ public final class VariableEscapeAnalyzer {
escaping[insn.getValue().getIndex()] = true; 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 @Override
public void visit(PutElementInstruction insn) { public void visit(PutElementInstruction insn) {
escaping[insn.getArray().getIndex()] = true; 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 @Override
public void visit(MonitorEnterInstruction insn) { public void visit(MonitorEnterInstruction insn) {
escaping[insn.getObjectRef().getIndex()] = true; escaping[insn.getObjectRef().getIndex()] = true;

View File

@ -564,6 +564,7 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
} }
optimizations.add(new ClassInitElimination()); optimizations.add(new ClassInitElimination());
optimizations.add(new UnreachableBasicBlockElimination()); optimizations.add(new UnreachableBasicBlockElimination());
optimizations.add(new UnusedVariableElimination());
return optimizations; return optimizations;
} }