JVM_IR: remove JvmArrayConstructorLowering

ExpressionCodegen already spills the stack before any loop, so it has
no effect.
This commit is contained in:
pyos
2021-05-04 16:17:08 +02:00
committed by TeamCityServer
parent 9f53d70109
commit a30cfc332d
4 changed files with 3 additions and 64 deletions
@@ -25,14 +25,13 @@ import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
import org.jetbrains.kotlin.util.OperatorNameConventions
class ArrayConstructorLowering(val context: CommonBackendContext) : IrElementTransformerVoidWithContext(), BodyLoweringPass {
class ArrayConstructorLowering(val context: CommonBackendContext) : BodyLoweringPass {
override fun lower(irBody: IrBody, container: IrDeclaration) {
irBody.transformChildrenVoid(ArrayConstructorTransformer(context, container as IrSymbolOwner))
}
}
open class ArrayConstructorTransformer(
private class ArrayConstructorTransformer(
val context: CommonBackendContext,
val container: IrSymbolOwner
) : IrElementTransformerVoidWithContext() {
@@ -63,8 +62,6 @@ open class ArrayConstructorTransformer(
val invokable = expression.getValueArgument(1)!!.transform(this, null)
val scope = (currentScope ?: createScope(container)).scope
return context.createIrBuilder(scope.scopeOwnerSymbol).irBlock(expression.startOffset, expression.endOffset) {
beforeArrayConstructorBody(this)
val index = createTmpVariable(irInt(0), isMutable = true)
val sizeVar = createTmpVariable(size)
val result = createTmpVariable(irCall(sizeConstructor, expression.type).apply {
@@ -89,13 +86,7 @@ open class ArrayConstructorTransformer(
+irSet(index.symbol, irCallOp(inc.symbol, index.type, irGet(index)))
}
}
afterArrayConstructorBody(this)
+irGet(result)
}
}
protected open fun beforeArrayConstructorBody(builder: IrBlockBuilder) {}
protected open fun afterArrayConstructorBody(builder: IrBlockBuilder) {}
}
@@ -67,7 +67,7 @@ private val provisionalFunctionExpressionPhase = makeIrFilePhase<CommonBackendCo
)
private val arrayConstructorPhase = makeIrFilePhase(
::JvmArrayConstructorLowering,
::ArrayConstructorLowering,
name = "ArrayConstructor",
description = "Transform `Array(size) { index -> value }` into a loop"
)
@@ -898,16 +898,6 @@ class JvmSymbols(
val runSuspendFunction: IrSimpleFunctionSymbol =
kotlinCoroutinesJvmInternalRunSuspendKt.functionByName("runSuspend")
private val inlineMarkerClass: IrClassSymbol = createClass(
JvmClassName.byInternalName("kotlin/jvm/internal/InlineMarker").fqNameForClassNameWithoutDollars
) { irClass ->
irClass.addFunction("beforeInlineCall", irBuiltIns.unitType, isStatic = true)
irClass.addFunction("afterInlineCall", irBuiltIns.unitType, isStatic = true)
}
val beforeInlineCall = inlineMarkerClass.functionByName("beforeInlineCall")
val afterInlineCall = inlineMarkerClass.functionByName("afterInlineCall")
companion object {
val FLEXIBLE_NULLABILITY_ANNOTATION_FQ_NAME =
IrBuiltIns.KOTLIN_INTERNAL_IR_FQN.child(Name.identifier("FlexibleNullability"))
@@ -1,42 +0,0 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.backend.jvm.lower
import org.jetbrains.kotlin.backend.common.BodyLoweringPass
import org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext
import org.jetbrains.kotlin.backend.common.lower.ArrayConstructorTransformer
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
import org.jetbrains.kotlin.ir.builders.IrBlockBuilder
import org.jetbrains.kotlin.ir.builders.irCall
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrSymbolOwner
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
class JvmArrayConstructorLowering(val context: JvmBackendContext) : IrElementTransformerVoidWithContext(), BodyLoweringPass {
override fun lower(irBody: IrBody, container: IrDeclaration) {
irBody.transformChildrenVoid(JvmArrayConstructorTransformer(context, container as IrSymbolOwner))
}
}
class JvmArrayConstructorTransformer(
private val jvmContext: JvmBackendContext,
container: IrSymbolOwner
) : ArrayConstructorTransformer(jvmContext, container) {
override fun beforeArrayConstructorBody(builder: IrBlockBuilder) {
with(builder) {
+irCall(jvmContext.ir.symbols.beforeInlineCall)
}
}
override fun afterArrayConstructorBody(builder: IrBlockBuilder) {
with(builder) {
+irCall(jvmContext.ir.symbols.afterInlineCall)
}
}
}