JVM_IR: remove JvmArrayConstructorLowering
ExpressionCodegen already spills the stack before any loop, so it has no effect.
This commit is contained in:
+2
-11
@@ -25,14 +25,13 @@ import org.jetbrains.kotlin.ir.util.*
|
|||||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
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) {
|
override fun lower(irBody: IrBody, container: IrDeclaration) {
|
||||||
irBody.transformChildrenVoid(ArrayConstructorTransformer(context, container as IrSymbolOwner))
|
irBody.transformChildrenVoid(ArrayConstructorTransformer(context, container as IrSymbolOwner))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open class ArrayConstructorTransformer(
|
private class ArrayConstructorTransformer(
|
||||||
val context: CommonBackendContext,
|
val context: CommonBackendContext,
|
||||||
val container: IrSymbolOwner
|
val container: IrSymbolOwner
|
||||||
) : IrElementTransformerVoidWithContext() {
|
) : IrElementTransformerVoidWithContext() {
|
||||||
@@ -63,8 +62,6 @@ open class ArrayConstructorTransformer(
|
|||||||
val invokable = expression.getValueArgument(1)!!.transform(this, null)
|
val invokable = expression.getValueArgument(1)!!.transform(this, null)
|
||||||
val scope = (currentScope ?: createScope(container)).scope
|
val scope = (currentScope ?: createScope(container)).scope
|
||||||
return context.createIrBuilder(scope.scopeOwnerSymbol).irBlock(expression.startOffset, expression.endOffset) {
|
return context.createIrBuilder(scope.scopeOwnerSymbol).irBlock(expression.startOffset, expression.endOffset) {
|
||||||
beforeArrayConstructorBody(this)
|
|
||||||
|
|
||||||
val index = createTmpVariable(irInt(0), isMutable = true)
|
val index = createTmpVariable(irInt(0), isMutable = true)
|
||||||
val sizeVar = createTmpVariable(size)
|
val sizeVar = createTmpVariable(size)
|
||||||
val result = createTmpVariable(irCall(sizeConstructor, expression.type).apply {
|
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)))
|
+irSet(index.symbol, irCallOp(inc.symbol, index.type, irGet(index)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
afterArrayConstructorBody(this)
|
|
||||||
|
|
||||||
+irGet(result)
|
+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(
|
private val arrayConstructorPhase = makeIrFilePhase(
|
||||||
::JvmArrayConstructorLowering,
|
::ArrayConstructorLowering,
|
||||||
name = "ArrayConstructor",
|
name = "ArrayConstructor",
|
||||||
description = "Transform `Array(size) { index -> value }` into a loop"
|
description = "Transform `Array(size) { index -> value }` into a loop"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -898,16 +898,6 @@ class JvmSymbols(
|
|||||||
val runSuspendFunction: IrSimpleFunctionSymbol =
|
val runSuspendFunction: IrSimpleFunctionSymbol =
|
||||||
kotlinCoroutinesJvmInternalRunSuspendKt.functionByName("runSuspend")
|
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 {
|
companion object {
|
||||||
val FLEXIBLE_NULLABILITY_ANNOTATION_FQ_NAME =
|
val FLEXIBLE_NULLABILITY_ANNOTATION_FQ_NAME =
|
||||||
IrBuiltIns.KOTLIN_INTERNAL_IR_FQN.child(Name.identifier("FlexibleNullability"))
|
IrBuiltIns.KOTLIN_INTERNAL_IR_FQN.child(Name.identifier("FlexibleNullability"))
|
||||||
|
|||||||
-42
@@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user