mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
When eliminating constant conditions, and removing dead branch,
also remove corresponding phi input to avoid clashes with further optimizations
This commit is contained in:
parent
3c4ec550c4
commit
8d9240df36
|
@ -13,7 +13,7 @@
|
||||||
<option name="MAIN_CLASS_NAME" value="" />
|
<option name="MAIN_CLASS_NAME" value="" />
|
||||||
<option name="METHOD_NAME" value="" />
|
<option name="METHOD_NAME" value="" />
|
||||||
<option name="TEST_OBJECT" value="package" />
|
<option name="TEST_OBJECT" value="package" />
|
||||||
<option name="VM_PARAMETERS" value="-ea -Dteavm.junit.target=target/js-tests -Dteavm.junit.js.runner=htmlunit -Dteavm.junit.js.threads=1 -Dteavm.junit.minified=true -Dteavm.junit.optimized=true" />
|
<option name="VM_PARAMETERS" value="-ea -Dteavm.junit.target=target/js-tests -Dteavm.junit.js.threads=1 -Dteavm.junit.minified=true -Dteavm.junit.optimized=true" />
|
||||||
<option name="PARAMETERS" value="" />
|
<option name="PARAMETERS" value="" />
|
||||||
<option name="WORKING_DIRECTORY" value="file://$MODULE_DIR$" />
|
<option name="WORKING_DIRECTORY" value="file://$MODULE_DIR$" />
|
||||||
<option name="ENV_VARIABLES" />
|
<option name="ENV_VARIABLES" />
|
||||||
|
|
|
@ -17,6 +17,7 @@ package org.teavm.model.optimization;
|
||||||
|
|
||||||
import org.teavm.model.BasicBlock;
|
import org.teavm.model.BasicBlock;
|
||||||
import org.teavm.model.Instruction;
|
import org.teavm.model.Instruction;
|
||||||
|
import org.teavm.model.Phi;
|
||||||
import org.teavm.model.Program;
|
import org.teavm.model.Program;
|
||||||
import org.teavm.model.instructions.BinaryBranchingCondition;
|
import org.teavm.model.instructions.BinaryBranchingCondition;
|
||||||
import org.teavm.model.instructions.BinaryBranchingInstruction;
|
import org.teavm.model.instructions.BinaryBranchingInstruction;
|
||||||
|
@ -25,6 +26,7 @@ import org.teavm.model.instructions.BranchingInstruction;
|
||||||
import org.teavm.model.instructions.IntegerConstantInstruction;
|
import org.teavm.model.instructions.IntegerConstantInstruction;
|
||||||
import org.teavm.model.instructions.JumpInstruction;
|
import org.teavm.model.instructions.JumpInstruction;
|
||||||
import org.teavm.model.instructions.NullConstantInstruction;
|
import org.teavm.model.instructions.NullConstantInstruction;
|
||||||
|
import org.teavm.model.util.InstructionTransitionExtractor;
|
||||||
|
|
||||||
public class ConstantConditionElimination implements MethodOptimization {
|
public class ConstantConditionElimination implements MethodOptimization {
|
||||||
private int[] constants;
|
private int[] constants;
|
||||||
|
@ -53,19 +55,39 @@ public class ConstantConditionElimination implements MethodOptimization {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
|
InstructionTransitionExtractor transitionExtractor = new InstructionTransitionExtractor();
|
||||||
for (int i = 0; i < program.basicBlockCount(); ++i) {
|
for (int i = 0; i < program.basicBlockCount(); ++i) {
|
||||||
BasicBlock block = program.basicBlockAt(i);
|
BasicBlock block = program.basicBlockAt(i);
|
||||||
Instruction insn = block.getLastInstruction();
|
Instruction insn = block.getLastInstruction();
|
||||||
BasicBlock target = constantTarget(insn);
|
BasicBlock target = constantTarget(insn);
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
|
block.getLastInstruction().acceptVisitor(transitionExtractor);
|
||||||
|
|
||||||
|
for (BasicBlock successor : transitionExtractor.getTargets()) {
|
||||||
|
if (successor != target) {
|
||||||
|
for (Phi phi : successor.getPhis()) {
|
||||||
|
for (int j = 0; j < phi.getIncomings().size(); ++j) {
|
||||||
|
if (phi.getIncomings().get(j).getSource() == block) {
|
||||||
|
phi.getIncomings().remove(j--);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
JumpInstruction jump = new JumpInstruction();
|
JumpInstruction jump = new JumpInstruction();
|
||||||
jump.setTarget(target);
|
jump.setTarget(target);
|
||||||
jump.setLocation(insn.getLocation());
|
jump.setLocation(insn.getLocation());
|
||||||
block.getLastInstruction().replace(jump);
|
block.getLastInstruction().replace(jump);
|
||||||
|
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (changed) {
|
||||||
|
new UnreachableBasicBlockEliminator().optimize(program);
|
||||||
|
}
|
||||||
|
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user