mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-10 08:54:11 -08:00
Fix bugs in nullness checker. Use it in LICM
This commit is contained in:
parent
2894c541f7
commit
6f92dadad5
|
@ -51,7 +51,7 @@ public class NullnessChecker {
|
||||||
notNullIncomings = new HashSet<>();
|
notNullIncomings = new HashSet<>();
|
||||||
notNull = new boolean[program.variableCount()];
|
notNull = new boolean[program.variableCount()];
|
||||||
nullLiteral = new boolean[program.variableCount()];
|
nullLiteral = new boolean[program.variableCount()];
|
||||||
phiOutputs = ProgramUtils.getPhiOutputs(program);
|
phiOutputs = ProgramUtils.getPhiOutputsByVariable(program);
|
||||||
graphBuilder = new GraphBuilder(program.variableCount());
|
graphBuilder = new GraphBuilder(program.variableCount());
|
||||||
|
|
||||||
Graph cfg = ProgramUtils.buildControlFlowGraph(program);
|
Graph cfg = ProgramUtils.buildControlFlowGraph(program);
|
||||||
|
|
|
@ -57,10 +57,15 @@ import org.teavm.model.instructions.SwitchInstruction;
|
||||||
import org.teavm.model.instructions.UnwrapArrayInstruction;
|
import org.teavm.model.instructions.UnwrapArrayInstruction;
|
||||||
|
|
||||||
public class LoopInvariantAnalyzer implements InstructionVisitor {
|
public class LoopInvariantAnalyzer implements InstructionVisitor {
|
||||||
|
private boolean[] notNull;
|
||||||
public boolean canMove;
|
public boolean canMove;
|
||||||
public boolean constant;
|
public boolean constant;
|
||||||
public boolean sideEffect;
|
public boolean sideEffect;
|
||||||
|
|
||||||
|
public LoopInvariantAnalyzer(boolean[] notNull) {
|
||||||
|
this.notNull = notNull;
|
||||||
|
}
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
canMove = false;
|
canMove = false;
|
||||||
constant = false;
|
constant = false;
|
||||||
|
@ -187,8 +192,10 @@ public class LoopInvariantAnalyzer implements InstructionVisitor {
|
||||||
@Override
|
@Override
|
||||||
public void visit(ArrayLengthInstruction insn) {
|
public void visit(ArrayLengthInstruction insn) {
|
||||||
canMove = true;
|
canMove = true;
|
||||||
|
if (!notNull[insn.getArray().getIndex()]) {
|
||||||
sideEffect = true;
|
sideEffect = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(CloneArrayInstruction insn) {
|
public void visit(CloneArrayInstruction insn) {
|
||||||
|
@ -197,8 +204,10 @@ public class LoopInvariantAnalyzer implements InstructionVisitor {
|
||||||
@Override
|
@Override
|
||||||
public void visit(UnwrapArrayInstruction insn) {
|
public void visit(UnwrapArrayInstruction insn) {
|
||||||
canMove = true;
|
canMove = true;
|
||||||
|
if (!notNull[insn.getArray().getIndex()]) {
|
||||||
sideEffect = true;
|
sideEffect = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(GetElementInstruction insn) {
|
public void visit(GetElementInstruction insn) {
|
||||||
|
@ -228,16 +237,16 @@ public class LoopInvariantAnalyzer implements InstructionVisitor {
|
||||||
@Override
|
@Override
|
||||||
public void visit(NullCheckInstruction insn) {
|
public void visit(NullCheckInstruction insn) {
|
||||||
canMove = true;
|
canMove = true;
|
||||||
|
if (!notNull[insn.getValue().getIndex()]) {
|
||||||
sideEffect = true;
|
sideEffect = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(MonitorEnterInstruction insn) {
|
public void visit(MonitorEnterInstruction insn) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(MonitorExitInstruction insn) {
|
public void visit(MonitorExitInstruction insn) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.teavm.common.*;
|
import org.teavm.common.*;
|
||||||
import org.teavm.model.*;
|
import org.teavm.model.*;
|
||||||
|
import org.teavm.model.analysis.NullnessChecker;
|
||||||
import org.teavm.model.instructions.*;
|
import org.teavm.model.instructions.*;
|
||||||
import org.teavm.model.util.*;
|
import org.teavm.model.util.*;
|
||||||
|
|
||||||
|
@ -53,7 +54,7 @@ public class LoopInvariantMotion implements MethodOptimization {
|
||||||
|
|
||||||
DefinitionExtractor defExtractor = new DefinitionExtractor();
|
DefinitionExtractor defExtractor = new DefinitionExtractor();
|
||||||
UsageExtractor useExtractor = new UsageExtractor();
|
UsageExtractor useExtractor = new UsageExtractor();
|
||||||
LoopInvariantAnalyzer analyzer = new LoopInvariantAnalyzer();
|
LoopInvariantAnalyzer analyzer = new LoopInvariantAnalyzer(new NullnessChecker().check(program));
|
||||||
CopyConstantVisitor constantCopier = new CopyConstantVisitor();
|
CopyConstantVisitor constantCopier = new CopyConstantVisitor();
|
||||||
int[][] loopExits = ControlFlowUtils.findLoopExits(graph);
|
int[][] loopExits = ControlFlowUtils.findLoopExits(graph);
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ import org.teavm.model.Program;
|
||||||
import org.teavm.model.TryCatchBlock;
|
import org.teavm.model.TryCatchBlock;
|
||||||
import org.teavm.model.TryCatchJoint;
|
import org.teavm.model.TryCatchJoint;
|
||||||
import org.teavm.model.Variable;
|
import org.teavm.model.Variable;
|
||||||
|
import org.teavm.model.analysis.NullnessChecker;
|
||||||
import org.teavm.model.util.BasicBlockMapper;
|
import org.teavm.model.util.BasicBlockMapper;
|
||||||
import org.teavm.model.util.DefinitionExtractor;
|
import org.teavm.model.util.DefinitionExtractor;
|
||||||
import org.teavm.model.util.InstructionCopyReader;
|
import org.teavm.model.util.InstructionCopyReader;
|
||||||
|
@ -222,7 +223,8 @@ class LoopInversionImpl {
|
||||||
private boolean isInversionProfitable(IntSet nodesToCopy) {
|
private boolean isInversionProfitable(IntSet nodesToCopy) {
|
||||||
UsageExtractor useExtractor = new UsageExtractor();
|
UsageExtractor useExtractor = new UsageExtractor();
|
||||||
DefinitionExtractor defExtractor = new DefinitionExtractor();
|
DefinitionExtractor defExtractor = new DefinitionExtractor();
|
||||||
LoopInvariantAnalyzer invariantAnalyzer = new LoopInvariantAnalyzer();
|
boolean[] notNull = new NullnessChecker().check(program);
|
||||||
|
LoopInvariantAnalyzer invariantAnalyzer = new LoopInvariantAnalyzer(notNull);
|
||||||
for (int node : nodes.toArray()) {
|
for (int node : nodes.toArray()) {
|
||||||
if (nodesToCopy.contains(node)) {
|
if (nodesToCopy.contains(node)) {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -163,6 +163,23 @@ public final class ProgramUtils {
|
||||||
return outputs;
|
return outputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<List<Incoming>> getPhiOutputsByVariable(Program program) {
|
||||||
|
List<List<Incoming>> outputs = new ArrayList<>(program.variableCount());
|
||||||
|
for (int i = 0; i < program.variableCount(); ++i) {
|
||||||
|
outputs.add(new ArrayList<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (BasicBlock block : program.getBasicBlocks()) {
|
||||||
|
for (Phi phi : block.getPhis()) {
|
||||||
|
for (Incoming incoming : phi.getIncomings()) {
|
||||||
|
outputs.get(incoming.getValue().getIndex()).add(incoming);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return outputs;
|
||||||
|
}
|
||||||
|
|
||||||
public static BasicBlock[] getVariableDefinitionPlaces(Program program) {
|
public static BasicBlock[] getVariableDefinitionPlaces(Program program) {
|
||||||
BasicBlock[] places = new BasicBlock[program.variableCount()];
|
BasicBlock[] places = new BasicBlock[program.variableCount()];
|
||||||
DefinitionExtractor defExtractor = new DefinitionExtractor();
|
DefinitionExtractor defExtractor = new DefinitionExtractor();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user