Fix bugs in loop inversion

This commit is contained in:
Alexey Andreev 2016-05-10 22:51:34 +03:00
parent 3c93b78902
commit 81b2f69225
3 changed files with 12 additions and 14 deletions

View File

@ -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=2" /> <option name="VM_PARAMETERS" value="-ea -Dteavm.junit.target=out -Dteavm.junit.js.runner=htmlunit -Dteavm.junit.js.threads=2" />
<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" />

View File

@ -157,6 +157,7 @@ class LoopInversionImpl {
final IntIntMap copiedVars = new IntIntOpenHashMap(); final IntIntMap copiedVars = new IntIntOpenHashMap();
final IntIntMap copiedNodes = new IntIntOpenHashMap(); final IntIntMap copiedNodes = new IntIntOpenHashMap();
final IntIntMap varDefinitionPoints = new IntIntOpenHashMap(); final IntIntMap varDefinitionPoints = new IntIntOpenHashMap();
final IntIntMap newHeadPhiMap = new IntIntOpenHashMap();
boolean shouldSkip; boolean shouldSkip;
LoopWithExits(int head, LoopWithExits parent) { LoopWithExits(int head, LoopWithExits parent) {
@ -188,9 +189,9 @@ class LoopInversionImpl {
collectVariablesToCopy(); collectVariablesToCopy();
copyCondition(); copyCondition();
moveBackEdges(); moveBackEdges();
putNewPhis();
removeInternalPhiInputsFromCondition(); removeInternalPhiInputsFromCondition();
removeExternalPhiInputsFromConditionCopy(); removeExternalPhiInputsFromConditionCopy();
putNewPhis();
adjustOutputPhis(); adjustOutputPhis();
return true; return true;
@ -354,21 +355,15 @@ class LoopInversionImpl {
BasicBlock block = program.basicBlockAt(headCopy); BasicBlock block = program.basicBlockAt(headCopy);
for (Phi phi : block.getPhis()) { for (Phi phi : block.getPhis()) {
List<Incoming> incomings = phi.getIncomings(); List<Incoming> incomings = phi.getIncomings();
List<Incoming> newIncomings = new ArrayList<>(incomings.size()); for (int i = 0; i < incomings.size(); ++i) {
for (Incoming incoming : incomings) { Incoming incoming = incomings.get(i);
if (nodesAndCopies.contains(incoming.getSource().getIndex())) { if (!nodesAndCopies.contains(incoming.getSource().getIndex())) {
newIncomings.add(incoming); incomings.remove(i--);
} else { } else {
for (int exit : exits.toArray()) { int var = incoming.getValue().getIndex();
Incoming newIncoming = new Incoming(); incoming.setValue(program.variableAt(newHeadPhiMap.getOrDefault(var, var)));
newIncoming.setValue(incoming.getValue());
newIncoming.setSource(program.basicBlockAt(exit));
newIncomings.add(newIncoming);
}
} }
} }
incomings.clear();
incomings.addAll(newIncomings);
} }
} }
@ -389,6 +384,7 @@ class LoopInversionImpl {
Phi phi = new Phi(); Phi phi = new Phi();
phi.setReceiver(program.createVariable()); phi.setReceiver(program.createVariable());
phiMap.put(var, phi.getReceiver().getIndex()); phiMap.put(var, phi.getReceiver().getIndex());
newHeadPhiMap.put(varCopy, phi.getReceiver().getIndex());
phisToAdd.add(phi); phisToAdd.add(phi);
for (int source : cfg.incomingEdges(bodyStart)) { for (int source : cfg.incomingEdges(bodyStart)) {

2
tests/out/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.js
run-test.html