mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Get rid of irreducible CFGs in input bytecode
This commit is contained in:
parent
4284bb2a6c
commit
6a4da94f2e
|
@ -57,6 +57,7 @@ import org.teavm.model.Variable;
|
||||||
import org.teavm.model.optimization.UnreachableBasicBlockEliminator;
|
import org.teavm.model.optimization.UnreachableBasicBlockEliminator;
|
||||||
import org.teavm.model.util.DefinitionExtractor;
|
import org.teavm.model.util.DefinitionExtractor;
|
||||||
import org.teavm.model.util.PhiUpdater;
|
import org.teavm.model.util.PhiUpdater;
|
||||||
|
import org.teavm.model.util.ProgramNodeSplittingBackend;
|
||||||
import org.teavm.model.util.ProgramUtils;
|
import org.teavm.model.util.ProgramUtils;
|
||||||
|
|
||||||
public class Parser {
|
public class Parser {
|
||||||
|
@ -86,6 +87,23 @@ public class Parser {
|
||||||
programParser.setFileName(fileName);
|
programParser.setFileName(fileName);
|
||||||
Program program = programParser.parse(node);
|
Program program = programParser.parse(node);
|
||||||
new UnreachableBasicBlockEliminator().optimize(program);
|
new UnreachableBasicBlockEliminator().optimize(program);
|
||||||
|
|
||||||
|
Graph cfg = ProgramUtils.buildControlFlowGraph(program);
|
||||||
|
if (GraphUtils.isIrreducible(cfg)) {
|
||||||
|
ProgramNodeSplittingBackend be = new ProgramNodeSplittingBackend(program);
|
||||||
|
int[] weights = new int[program.basicBlockCount()];
|
||||||
|
for (int i = 0; i < weights.length; ++i) {
|
||||||
|
int count = 0;
|
||||||
|
Instruction insn = program.basicBlockAt(i).getFirstInstruction();
|
||||||
|
while (insn != null) {
|
||||||
|
count++;
|
||||||
|
insn = insn.getNext();
|
||||||
|
}
|
||||||
|
weights[i] = count;
|
||||||
|
}
|
||||||
|
GraphUtils.splitIrreducibleGraph(cfg, weights, be);
|
||||||
|
}
|
||||||
|
|
||||||
PhiUpdater phiUpdater = new PhiUpdater();
|
PhiUpdater phiUpdater = new PhiUpdater();
|
||||||
Variable[] argumentMapping = applySignature(program, method.getParameterTypes());
|
Variable[] argumentMapping = applySignature(program, method.getParameterTypes());
|
||||||
phiUpdater.updatePhis(program, argumentMapping);
|
phiUpdater.updatePhis(program, argumentMapping);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user