mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Fixes register allocation bugs
This commit is contained in:
parent
b7917f2511
commit
0eb4e54e51
|
@ -118,7 +118,7 @@ public class LivenessAnalyzer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean dominates(int a, int b) {
|
private boolean dominates(int a, int b) {
|
||||||
return domLeft[a] <= domLeft[b] && domRight[a] >= domRight[b];
|
return domLeft[a] < domLeft[b] && domRight[a] > domRight[b];
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Task {
|
private static class Task {
|
||||||
|
|
|
@ -15,9 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package org.teavm.model.util;
|
package org.teavm.model.util;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import org.teavm.common.DisjointSet;
|
import org.teavm.common.DisjointSet;
|
||||||
import org.teavm.common.Graph;
|
import org.teavm.common.Graph;
|
||||||
import org.teavm.model.*;
|
import org.teavm.model.*;
|
||||||
|
@ -42,7 +40,7 @@ public class RegisterAllocator {
|
||||||
int[] classArray = congruenceClasses.pack(program.variableCount());
|
int[] classArray = congruenceClasses.pack(program.variableCount());
|
||||||
int[] colors = new int[program.variableCount()];
|
int[] colors = new int[program.variableCount()];
|
||||||
Arrays.fill(colors, -1);
|
Arrays.fill(colors, -1);
|
||||||
for (int i = 0; i < method.parameterCount(); ++i) {
|
for (int i = 0; i <= method.parameterCount(); ++i) {
|
||||||
colors[i] = i;
|
colors[i] = i;
|
||||||
}
|
}
|
||||||
GraphColorer colorer = new GraphColorer();
|
GraphColorer colorer = new GraphColorer();
|
||||||
|
@ -61,6 +59,7 @@ public class RegisterAllocator {
|
||||||
private List<PhiArgumentCopy> insertPhiArgumentsCopies(Program program) {
|
private List<PhiArgumentCopy> insertPhiArgumentsCopies(Program program) {
|
||||||
List<PhiArgumentCopy> copies = new ArrayList<>();
|
List<PhiArgumentCopy> copies = new ArrayList<>();
|
||||||
for (int i = 0; i < program.basicBlockCount(); ++i) {
|
for (int i = 0; i < program.basicBlockCount(); ++i) {
|
||||||
|
Map<BasicBlock, BasicBlock> blockMap = new HashMap<>();
|
||||||
for (final Phi phi : program.basicBlockAt(i).getPhis()) {
|
for (final Phi phi : program.basicBlockAt(i).getPhis()) {
|
||||||
for (Incoming incoming : phi.getIncomings()) {
|
for (Incoming incoming : phi.getIncomings()) {
|
||||||
PhiArgumentCopy copy = new PhiArgumentCopy();
|
PhiArgumentCopy copy = new PhiArgumentCopy();
|
||||||
|
@ -70,6 +69,12 @@ public class RegisterAllocator {
|
||||||
copyInstruction.setReceiver(program.createVariable());
|
copyInstruction.setReceiver(program.createVariable());
|
||||||
copyInstruction.setAssignee(incoming.getValue());
|
copyInstruction.setAssignee(incoming.getValue());
|
||||||
copy.var = copyInstruction.getReceiver().getIndex();
|
copy.var = copyInstruction.getReceiver().getIndex();
|
||||||
|
BasicBlock source = blockMap.get(incoming.getSource());
|
||||||
|
if (source == null) {
|
||||||
|
source = incoming.getSource();
|
||||||
|
} else {
|
||||||
|
incoming.setSource(source);
|
||||||
|
}
|
||||||
if (incoming.getSource().getLastInstruction() instanceof JumpInstruction) {
|
if (incoming.getSource().getLastInstruction() instanceof JumpInstruction) {
|
||||||
copy.index = incoming.getSource().getInstructions().size() - 1;
|
copy.index = incoming.getSource().getInstructions().size() - 1;
|
||||||
copy.block = incoming.getSource();
|
copy.block = incoming.getSource();
|
||||||
|
@ -89,10 +94,12 @@ public class RegisterAllocator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
blockMap.put(source, copyBlock);
|
||||||
incoming.setSource(copyBlock);
|
incoming.setSource(copyBlock);
|
||||||
copy.index = 0;
|
copy.index = 0;
|
||||||
copy.block = incoming.getSource();
|
copy.block = incoming.getSource();
|
||||||
}
|
}
|
||||||
|
incoming.setValue(copyInstruction.getReceiver());
|
||||||
copies.add(copy);
|
copies.add(copy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,7 @@ import org.teavm.model.MethodHolder;
|
||||||
*/
|
*/
|
||||||
public class ClassSetOptimizer {
|
public class ClassSetOptimizer {
|
||||||
private List<MethodOptimization> optimizations = Arrays.<MethodOptimization>asList(
|
private List<MethodOptimization> optimizations = Arrays.<MethodOptimization>asList(
|
||||||
new CommonSubexpressionElimination(), new UnusedVariableElimination(),
|
new CommonSubexpressionElimination(), new UnusedVariableElimination());
|
||||||
new EmptyBlockElimination());
|
|
||||||
|
|
||||||
public void optimizeAll(ListableClassHolderSource classSource) {
|
public void optimizeAll(ListableClassHolderSource classSource) {
|
||||||
for (String className : classSource.getClassNames()) {
|
for (String className : classSource.getClassNames()) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user