Rewrite local var increment optimization

This commit is contained in:
Michael Bogdanov
2014-11-06 18:32:31 +03:00
parent 425f0984c7
commit 7d1fd47569
3 changed files with 23 additions and 12 deletions
@@ -54,19 +54,15 @@ public class Increment extends IntrinsicMethod {
assert isPrimitive(returnType) : "Return type of Increment intrinsic should be of primitive type : " + returnType;
if (arguments.size() > 0) {
JetExpression operand = JetPsiUtil.deparenthesize(arguments.get(0));
if (operand instanceof JetReferenceExpression && returnType == Type.INT_TYPE) {
int index = codegen.indexOfLocal((JetReferenceExpression) operand);
if (index >= 0) {
JetType operandType = codegen.getBindingContext().get(EXPRESSION_TYPE, operand);
if (operandType != null && KotlinBuiltIns.getInstance().isPrimitiveType(operandType)) {
StackValue.preIncrementForLocalVar(index, myDelta).put(returnType, v);
return returnType;
}
}
JetExpression operand = arguments.get(0);
StackValue stackValue = codegen.genQualified(receiver, operand);
StackValue result;
if (stackValue instanceof StackValue.Local && Type.INT_TYPE.equals(stackValue.type)) {
result = StackValue.preIncrementForLocalVar(((StackValue.Local) stackValue).index, myDelta);
} else {
result = StackValue.preIncrement(returnType, stackValue, myDelta, this, null, codegen);
}
StackValue value = StackValue.preIncrement(returnType, codegen.genQualified(receiver, operand), myDelta, this, null, codegen);
value.put(returnType, v);
result.put(returnType, v);
}
else {
receiver.put(returnType, v);
@@ -0,0 +1,9 @@
fun main(args: Array<String>) {
var i = 10
++i
++(@l i)
++(i: Int)
++(@l (i: Int))
}
// 4 IINC
@@ -163,6 +163,12 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
doTest(fileName);
}
@TestMetadata("prefixIntVarIncrement.kt")
public void testPrefixIntVarIncrement() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/prefixIntVarIncrement.kt");
doTest(fileName);
}
@TestMetadata("privateDefaultArgs.kt")
public void testPrivateDefaultArgs() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/privateDefaultArgs.kt");