Optimize coercion to Unit.

POP operations are backward-propagated.

Operation can't be transformed if its result is moved within stack
(by DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, or SWAP).

Unnecessary operations are replaced with NOPs (for debugger).
Unnecessary NOPs are removed.

KT-9922 Suboptimal generation for simple safe call with unused return value
KT-11116 Optimize methods returning Unit
This commit is contained in:
Dmitry Petrov
2016-04-05 17:27:01 +03:00
parent c4a568efff
commit f1b061d662
12 changed files with 433 additions and 84 deletions
@@ -575,6 +575,51 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
}
}
@TestMetadata("compiler/testData/codegen/bytecodeText/coercionToUnitOptimization")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class CoercionToUnitOptimization extends AbstractBytecodeTextTest {
public void testAllFilesPresentInCoercionToUnitOptimization() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/bytecodeText/coercionToUnitOptimization"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("nopInlineFuns.kt")
public void testNopInlineFuns() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/coercionToUnitOptimization/nopInlineFuns.kt");
doTest(fileName);
}
@TestMetadata("returnsUnit.kt")
public void testReturnsUnit() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/coercionToUnitOptimization/returnsUnit.kt");
doTest(fileName);
}
@TestMetadata("safeCall.kt")
public void testSafeCall() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/coercionToUnitOptimization/safeCall.kt");
doTest(fileName);
}
@TestMetadata("safeCallWithReturnValue.kt")
public void testSafeCallWithReturnValue() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/coercionToUnitOptimization/safeCallWithReturnValue.kt");
doTest(fileName);
}
@TestMetadata("safeLet.kt")
public void testSafeLet() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/coercionToUnitOptimization/safeLet.kt");
doTest(fileName);
}
@TestMetadata("tryInlined.kt")
public void testTryInlined() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/coercionToUnitOptimization/tryInlined.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/bytecodeText/conditions")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)