[JVM] Move initLocals method into FastAnalyzer
This commit is contained in:
+24
-1
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.codegen.optimization.common
|
|||||||
import org.jetbrains.kotlin.codegen.inline.insnText
|
import org.jetbrains.kotlin.codegen.inline.insnText
|
||||||
import org.jetbrains.kotlin.utils.SmartList
|
import org.jetbrains.kotlin.utils.SmartList
|
||||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
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.*
|
||||||
import org.jetbrains.org.objectweb.asm.tree.analysis.AnalyzerException
|
import org.jetbrains.org.objectweb.asm.tree.analysis.AnalyzerException
|
||||||
import org.jetbrains.org.objectweb.asm.tree.analysis.Frame
|
import org.jetbrains.org.objectweb.asm.tree.analysis.Frame
|
||||||
@@ -76,7 +77,29 @@ abstract class FastAnalyzer<V : Value, I : Interpreter<V>, F : Frame<V>>(
|
|||||||
|
|
||||||
protected open fun beforeAnalyze() {}
|
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)
|
protected abstract fun mergeControlFlowEdge(dest: Int, frame: F, canReuse: Boolean = false)
|
||||||
|
|
||||||
|
|||||||
-21
@@ -104,27 +104,6 @@ open class FastMethodAnalyzer<V : Value>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun initLocals(current: Frame<V>) {
|
|
||||||
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<V>, insn: Int) {
|
override fun visitOpInsn(insnNode: AbstractInsnNode, current: Frame<V>, insn: Int) {
|
||||||
mergeControlFlowEdge(insn + 1, current)
|
mergeControlFlowEdge(insn + 1, current)
|
||||||
}
|
}
|
||||||
|
|||||||
-24
@@ -137,30 +137,6 @@ internal open class FastStackAnalyzer<V : Value>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun initLocals(current: Frame<V>) {
|
|
||||||
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<V>, canReuse: Boolean) {
|
override fun mergeControlFlowEdge(dest: Int, frame: Frame<V>, canReuse: Boolean) {
|
||||||
val destFrame = getFrame(dest)
|
val destFrame = getFrame(dest)
|
||||||
if (destFrame == null) {
|
if (destFrame == null) {
|
||||||
|
|||||||
-24
@@ -188,30 +188,6 @@ class FastStoreLoadAnalyzer<V : StoreLoadValue>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun initLocals(current: StoreLoadFrame<V>) {
|
|
||||||
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<V>, canReuse: Boolean) {
|
override fun mergeControlFlowEdge(dest: Int, frame: StoreLoadFrame<V>, canReuse: Boolean) {
|
||||||
val oldFrame = getFrame(dest)
|
val oldFrame = getFrame(dest)
|
||||||
val changes = when {
|
val changes = when {
|
||||||
|
|||||||
Reference in New Issue
Block a user