JVM_IR fixes after review

This commit is contained in:
Dmitry Petrov
2021-08-24 13:00:49 +03:00
committed by TeamCityServer
parent f4dd75e769
commit c30b23ed01
6 changed files with 12 additions and 22 deletions
@@ -646,11 +646,6 @@ class ExpressionCodegen(
return MaterialValue(this, type, expression.symbol.owner.realType) return MaterialValue(this, type, expression.symbol.owner.realType)
} }
private fun IrValueDeclaration.isTemporaryVal() =
this is IrVariable &&
!this.isVar &&
this.origin == IrDeclarationOrigin.IR_TEMPORARY_VARIABLE
internal fun genOrGetLocal(expression: IrExpression, type: Type, parameterType: IrType, data: BlockInfo): StackValue = internal fun genOrGetLocal(expression: IrExpression, type: Type, parameterType: IrType, data: BlockInfo): StackValue =
if (expression is IrGetValue) if (expression is IrGetValue)
StackValue.local( StackValue.local(
@@ -1229,7 +1224,7 @@ class ExpressionCodegen(
val afterStore = markNewLabel() val afterStore = markNewLabel()
val catchBody = clause.result val catchBody = clause.result
var catchBlockInfo = BlockInfo(data) val catchBlockInfo = BlockInfo(data)
catchBlockInfo.variables.add(VariableInfo(parameter, index, descriptorType, afterStore)) catchBlockInfo.variables.add(VariableInfo(parameter, index, descriptorType, afterStore))
val catchResult = catchBody.accept(this, catchBlockInfo) val catchResult = catchBody.accept(this, catchBlockInfo)
@@ -322,7 +322,10 @@ class JvmOptimizationLowering(val context: JvmBackendContext) : FileLoweringPass
initializer initializer
} }
is IrValueParameter -> is IrValueParameter ->
return initializer return if (initializerValue.isAssignable)
null
else
initializer
} }
} }
@@ -394,9 +397,10 @@ class JvmOptimizationLowering(val context: JvmBackendContext) : FileLoweringPass
} }
if (expression.origin == IrStatementOrigin.WHEN) { if (expression.origin == IrStatementOrigin.WHEN) {
// Don't optimize out 'when' subject - otherwise we might get somewhat weird debugging behavior. // Don't optimize out 'when' subject initialized with a variable,
// otherwise we might get somewhat weird debugging behavior.
val subject = expression.statements.firstOrNull() val subject = expression.statements.firstOrNull()
if (subject is IrVariable) { if (subject is IrVariable && subject.initializer is IrGetValue) {
dontTouchTemporaryVals.add(subject) dontTouchTemporaryVals.add(subject)
} }
} }
@@ -8,10 +8,5 @@ fun test(x: A?) {
x?.foo() x?.foo()
} }
// JVM_TEMPLATES
// 2 POP // 2 POP
// 0 ACONST_NULL // 0 ACONST_NULL
// JVM_IR_TEMPLATES
// 2 POP
// 0 ACONST_NULL
@@ -19,9 +19,4 @@ fun test(ss: List<String?>) {
// 0 INVOKESTATIC java/lang/Boolean\.valueOf // 0 INVOKESTATIC java/lang/Boolean\.valueOf
// 0 CHECKCAST java/lang/Boolean // 0 CHECKCAST java/lang/Boolean
// 0 ACONST_NULL // 0 ACONST_NULL
// JVM_TEMPLATES
// 2 POP
// JVM_IR_TEMPLATES
// 2 POP // 2 POP
@@ -1,5 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
@Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER") @Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
@kotlin.internal.InlineOnly @kotlin.internal.InlineOnly
inline fun inlineOnlyFun(): Int { inline fun inlineOnlyFun(): Int {
+4 -1
View File
@@ -12,9 +12,12 @@ fun box() {
} }
// JVM_IR and JVM backends have different heuristics for when to use a switch. // JVM_IR and JVM backends have different heuristics for when to use a switch.
// JVM_IR inlines constant value subject and folds unreachable branches.
// LINENUMBERS // LINENUMBERS
// test.kt:4 box // test.kt:4 box
// LINENUMBERS JVM_IR
// test.kt:5 box
// test.kt:7 box
// LINENUMBERS
// test.kt:10 box // test.kt:10 box
// test.kt:12 box // test.kt:12 box