From 2c4c3a73b8f8e7b2d4a71496f6d2e5b5d4aa5eee Mon Sep 17 00:00:00 2001 From: Ivan Kylchik Date: Fri, 25 Aug 2023 12:10:02 +0200 Subject: [PATCH] [JVM] Move `initLocals` method into `FastAnalyzer` --- .../optimization/common/FastAnalyzer.kt | 25 ++++++++++++++++++- .../optimization/common/FastMethodAnalyzer.kt | 21 ---------------- .../fixStack/FastStackAnalyzer.kt | 24 ------------------ .../temporaryVals/FastStoreLoadAnalyzer.kt | 24 ------------------ 4 files changed, 24 insertions(+), 70 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/common/FastAnalyzer.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/common/FastAnalyzer.kt index 4664f14e509..50f7bf5b637 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/common/FastAnalyzer.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/common/FastAnalyzer.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.codegen.optimization.common import org.jetbrains.kotlin.codegen.inline.insnText import org.jetbrains.kotlin.utils.SmartList import org.jetbrains.org.objectweb.asm.Opcodes +import org.jetbrains.org.objectweb.asm.Type import org.jetbrains.org.objectweb.asm.tree.* import org.jetbrains.org.objectweb.asm.tree.analysis.AnalyzerException import org.jetbrains.org.objectweb.asm.tree.analysis.Frame @@ -76,7 +77,29 @@ abstract class FastAnalyzer, F : Frame>( protected open fun beforeAnalyze() {} - protected abstract fun initLocals(current: F) + private fun initLocals(current: F) { + current.setReturn(interpreter.newReturnTypeValue(Type.getReturnType(method.desc))) + val args = Type.getArgumentTypes(method.desc) + var local = 0 + val isInstanceMethod = (method.access and Opcodes.ACC_STATIC) == 0 + if (isInstanceMethod) { + val ctype = Type.getObjectType(owner) + current.setLocal(local, interpreter.newParameterValue(true, local, ctype)) + local++ + } + for (arg in args) { + current.setLocal(local, interpreter.newParameterValue(isInstanceMethod, local, arg)) + local++ + if (arg.size == 2) { + current.setLocal(local, interpreter.newEmptyValue(local)) + local++ + } + } + while (local < method.maxLocals) { + current.setLocal(local, interpreter.newEmptyValue(local)) + local++ + } + } protected abstract fun mergeControlFlowEdge(dest: Int, frame: F, canReuse: Boolean = false) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/common/FastMethodAnalyzer.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/common/FastMethodAnalyzer.kt index 3f9bf46b996..3235fa847dc 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/common/FastMethodAnalyzer.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/common/FastMethodAnalyzer.kt @@ -104,27 +104,6 @@ open class FastMethodAnalyzer } } - override fun initLocals(current: Frame) { - current.setReturn(interpreter.newReturnTypeValue(Type.getReturnType(method.desc))) - val args = Type.getArgumentTypes(method.desc) - var local = 0 - val isInstanceMethod = (method.access and Opcodes.ACC_STATIC) == 0 - if (isInstanceMethod) { - val ctype = Type.getObjectType(owner) - current.setLocal(local, interpreter.newParameterValue(true, local, ctype)) - local++ - } - for (arg in args) { - current.setLocal(local++, interpreter.newValue(arg)) - if (arg.size == 2) { - current.setLocal(local++, interpreter.newValue(null)) - } - } - while (local < method.maxLocals) { - current.setLocal(local++, interpreter.newValue(null)) - } - } - override fun visitOpInsn(insnNode: AbstractInsnNode, current: Frame, insn: Int) { mergeControlFlowEdge(insn + 1, current) } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/fixStack/FastStackAnalyzer.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/fixStack/FastStackAnalyzer.kt index 3faccffb432..f65ba7b6664 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/fixStack/FastStackAnalyzer.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/fixStack/FastStackAnalyzer.kt @@ -137,30 +137,6 @@ internal open class FastStackAnalyzer( } } - override fun initLocals(current: Frame) { - current.setReturn(interpreter.newValue(Type.getReturnType(method.desc))) - val args = Type.getArgumentTypes(method.desc) - var local = 0 - val isInstanceMethod = (method.access and Opcodes.ACC_STATIC) == 0 - if (isInstanceMethod) { - val ctype = Type.getObjectType(owner) - current.setLocal(local, interpreter.newParameterValue(true, local, ctype)) - local++ - } - for (arg in args) { - current.setLocal(local, interpreter.newParameterValue(isInstanceMethod, local, arg)) - local++ - if (arg.size == 2) { - current.setLocal(local, interpreter.newEmptyValue(local)) - local++ - } - } - while (local < method.maxLocals) { - current.setLocal(local, interpreter.newEmptyValue(local)) - local++ - } - } - override fun mergeControlFlowEdge(dest: Int, frame: Frame, canReuse: Boolean) { val destFrame = getFrame(dest) if (destFrame == null) { diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/temporaryVals/FastStoreLoadAnalyzer.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/temporaryVals/FastStoreLoadAnalyzer.kt index 48ba4242ec5..a8edf156465 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/temporaryVals/FastStoreLoadAnalyzer.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/temporaryVals/FastStoreLoadAnalyzer.kt @@ -188,30 +188,6 @@ class FastStoreLoadAnalyzer( } } - override fun initLocals(current: StoreLoadFrame) { - current.setReturn(interpreter.newReturnTypeValue(Type.getReturnType(method.desc))) - val args = Type.getArgumentTypes(method.desc) - var local = 0 - val isInstanceMethod = (method.access and Opcodes.ACC_STATIC) == 0 - if (isInstanceMethod) { - val ctype = Type.getObjectType(owner) - current.setLocal(local, interpreter.newParameterValue(true, local, ctype)) - local++ - } - for (arg in args) { - current.setLocal(local, interpreter.newParameterValue(isInstanceMethod, local, arg)) - local++ - if (arg.size == 2) { - current.setLocal(local, interpreter.newEmptyValue(local)) - local++ - } - } - while (local < method.maxLocals) { - current.setLocal(local, interpreter.newEmptyValue(local)) - local++ - } - } - override fun mergeControlFlowEdge(dest: Int, frame: StoreLoadFrame, canReuse: Boolean) { val oldFrame = getFrame(dest) val changes = when {