mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Improve inlining
This commit is contained in:
parent
146776ff55
commit
eb3490dba0
|
@ -408,7 +408,8 @@ public class Renderer implements RenderingManager {
|
||||||
if (clinit != null && context.isDynamicInitializer(cls.getName())) {
|
if (clinit != null && context.isDynamicInitializer(cls.getName())) {
|
||||||
renderCallClinit(clinit, cls);
|
renderCallClinit(clinit, cls);
|
||||||
}
|
}
|
||||||
if (!cls.getClassHolder().getModifiers().contains(ElementModifier.INTERFACE)) {
|
if (!cls.getClassHolder().hasModifier(ElementModifier.INTERFACE)
|
||||||
|
&& !cls.getClassHolder().hasModifier(ElementModifier.ABSTRACT)) {
|
||||||
for (PreparedMethod method : cls.getMethods()) {
|
for (PreparedMethod method : cls.getMethods()) {
|
||||||
if (!method.methodHolder.getModifiers().contains(ElementModifier.STATIC)) {
|
if (!method.methodHolder.getModifiers().contains(ElementModifier.STATIC)) {
|
||||||
if (method.reference.getName().equals("<init>")) {
|
if (method.reference.getName().equals("<init>")) {
|
||||||
|
|
|
@ -124,26 +124,37 @@ public class DefaultInliningStrategy implements InliningStrategy {
|
||||||
public void invoke(VariableReader receiver, VariableReader instance, MethodReference method,
|
public void invoke(VariableReader receiver, VariableReader instance, MethodReference method,
|
||||||
List<? extends VariableReader> arguments, InvocationType type) {
|
List<? extends VariableReader> arguments, InvocationType type) {
|
||||||
if (type == InvocationType.SPECIAL && context != null && context.isUsedOnce(method)) {
|
if (type == InvocationType.SPECIAL && context != null && context.isUsedOnce(method)) {
|
||||||
callsToUsedOnceMethods = true;
|
ProgramReader program = context.getProgram(method);
|
||||||
|
if (!isTrivialCall(program)) {
|
||||||
|
callsToUsedOnceMethods = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isTrivialCall(ProgramReader program) {
|
||||||
|
if (program == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Complexity complexity = getComplexity(program, context);
|
||||||
|
return complexity.score <= 1 && !complexity.callsToUsedOnceMethods;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void choose(VariableReader condition, List<? extends SwitchTableEntryReader> table,
|
public void choose(VariableReader condition, List<? extends SwitchTableEntryReader> table,
|
||||||
BasicBlockReader defaultTarget) {
|
BasicBlockReader defaultTarget) {
|
||||||
complexity += 3;
|
complexity += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void jumpIf(BranchingCondition cond, VariableReader operand, BasicBlockReader consequent,
|
public void jumpIf(BranchingCondition cond, VariableReader operand, BasicBlockReader consequent,
|
||||||
BasicBlockReader alternative) {
|
BasicBlockReader alternative) {
|
||||||
complexity += 2;
|
complexity += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void jumpIf(BinaryBranchingCondition cond, VariableReader first, VariableReader second,
|
public void jumpIf(BinaryBranchingCondition cond, VariableReader first, VariableReader second,
|
||||||
BasicBlockReader consequent, BasicBlockReader alternative) {
|
BasicBlockReader consequent, BasicBlockReader alternative) {
|
||||||
complexity += 2;
|
complexity += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -155,6 +166,11 @@ public class DefaultInliningStrategy implements InliningStrategy {
|
||||||
public void exit(VariableReader valueToReturn) {
|
public void exit(VariableReader valueToReturn) {
|
||||||
complexity--;
|
complexity--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void raise(VariableReader exception) {
|
||||||
|
complexity--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class Complexity {
|
static class Complexity {
|
||||||
|
|
|
@ -500,6 +500,16 @@ public class Inlining {
|
||||||
return methodsUsedOnce.contains(method);
|
return methodsUsedOnce.contains(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ProgramReader getProgram(MethodReference method) {
|
||||||
|
ClassReader cls = dependencyInfo.getClassSource().get(method.getClassName());
|
||||||
|
if (cls == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
MethodReader methodReader = cls.getMethod(method.getDescriptor());
|
||||||
|
return methodReader != null ? methodReader.getProgram() : null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getDepth() {
|
public int getDepth() {
|
||||||
return depth;
|
return depth;
|
||||||
|
|
|
@ -16,9 +16,12 @@
|
||||||
package org.teavm.model.optimization;
|
package org.teavm.model.optimization;
|
||||||
|
|
||||||
import org.teavm.model.MethodReference;
|
import org.teavm.model.MethodReference;
|
||||||
|
import org.teavm.model.ProgramReader;
|
||||||
|
|
||||||
public interface InliningContext {
|
public interface InliningContext {
|
||||||
boolean isUsedOnce(MethodReference method);
|
boolean isUsedOnce(MethodReference method);
|
||||||
|
|
||||||
|
ProgramReader getProgram(MethodReference method);
|
||||||
|
|
||||||
int getDepth();
|
int getDepth();
|
||||||
}
|
}
|
||||||
|
|
|
@ -837,7 +837,7 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isVirtual(MethodReference method) {
|
boolean isVirtual(MethodReference method) {
|
||||||
if (method.getName().equals("<init>") || method.getName().equals("<clinit>")) {
|
if (method.getName().equals("<clinit>")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return virtualMethods == null || virtualMethods.contains(method)
|
return virtualMethods == null || virtualMethods.contains(method)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user