[JVM] Reuse visitNopInsn method in all Fast...Analyzer classes

This commit is contained in:
Ivan Kylchik
2023-09-06 10:59:18 +02:00
committed by Space Team
parent ed95ebc585
commit 58473b94a7
4 changed files with 20 additions and 11 deletions
@@ -103,9 +103,9 @@ abstract class FastAnalyzer<V : Value, I : Interpreter<V>, F : Frame<V>>(
} }
} }
protected fun processControlFlowEdge(current: F, insnNode: AbstractInsnNode, jump: Int) { private fun processControlFlowEdge(current: F, insnNode: AbstractInsnNode, jump: Int, canReuse: Boolean = false) {
if (visitControlFlowEdge(insnNode, jump)) { if (visitControlFlowEdge(insnNode, jump)) {
mergeControlFlowEdge(jump, current) mergeControlFlowEdge(jump, current, canReuse)
} }
} }
@@ -148,6 +148,10 @@ abstract class FastAnalyzer<V : Value, I : Interpreter<V>, F : Frame<V>>(
} }
} }
protected fun visitNopInsn(insnNode: AbstractInsnNode, current: F, insn: Int) {
processControlFlowEdge(current, insnNode, insn + 1, canReuse = true)
}
private fun visitOpInsn(insnNode: AbstractInsnNode, current: F, insn: Int) { private fun visitOpInsn(insnNode: AbstractInsnNode, current: F, insn: Int) {
processControlFlowEdge(current, insnNode, insn + 1) processControlFlowEdge(current, insnNode, insn + 1)
} }
@@ -77,7 +77,7 @@ class FastMethodAnalyzer<V : Value>
insnType == AbstractInsnNode.FRAME || insnType == AbstractInsnNode.FRAME ||
insnOpcode == Opcodes.NOP insnOpcode == Opcodes.NOP
) { ) {
mergeControlFlowEdge(insnIndex + 1, currentlyAnalyzing, canReuse = true) visitNopInsn(insnNode, currentlyAnalyzing, insnIndex)
} else { } else {
current.init(currentlyAnalyzing).execute(insnNode, interpreter) current.init(currentlyAnalyzing).execute(insnNode, interpreter)
visitMeaningfulInstruction(insnNode, insnType, insnOpcode, current, insnIndex) visitMeaningfulInstruction(insnNode, insnType, insnOpcode, current, insnIndex)
@@ -36,7 +36,8 @@ package org.jetbrains.kotlin.codegen.optimization.fixStack
import org.jetbrains.kotlin.codegen.optimization.common.FastAnalyzer import org.jetbrains.kotlin.codegen.optimization.common.FastAnalyzer
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.Type
import org.jetbrains.org.objectweb.asm.tree.* import org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode
import org.jetbrains.org.objectweb.asm.tree.MethodNode
import org.jetbrains.org.objectweb.asm.tree.analysis.Frame import org.jetbrains.org.objectweb.asm.tree.analysis.Frame
import org.jetbrains.org.objectweb.asm.tree.analysis.Interpreter import org.jetbrains.org.objectweb.asm.tree.analysis.Interpreter
import org.jetbrains.org.objectweb.asm.tree.analysis.Value import org.jetbrains.org.objectweb.asm.tree.analysis.Value
@@ -66,7 +67,11 @@ internal open class FastStackAnalyzer<V : Value, F : Frame<V>>(
current: F, current: F,
handler: F, handler: F,
) { ) {
if (insnType == AbstractInsnNode.LABEL || insnType == AbstractInsnNode.LINE || insnType == AbstractInsnNode.FRAME) { if (insnType == AbstractInsnNode.LABEL ||
insnType == AbstractInsnNode.LINE ||
insnType == AbstractInsnNode.FRAME ||
insnOpcode == Opcodes.NOP
) {
visitNopInsn(insnNode, currentlyAnalyzing, insnIndex) visitNopInsn(insnNode, currentlyAnalyzing, insnIndex)
} else { } else {
current.init(currentlyAnalyzing) current.init(currentlyAnalyzing)
@@ -88,10 +93,6 @@ internal open class FastStackAnalyzer<V : Value, F : Frame<V>>(
} }
} }
private fun visitNopInsn(insnNode: AbstractInsnNode, f: F, insn: Int) {
processControlFlowEdge(f, insnNode, insn + 1)
}
override fun mergeControlFlowEdge(dest: Int, frame: F, canReuse: Boolean) { override fun mergeControlFlowEdge(dest: Int, frame: F, canReuse: Boolean) {
val oldFrame = getFrame(dest) val oldFrame = getFrame(dest)
val changes = when { val changes = when {
@@ -79,8 +79,12 @@ class FastStoreLoadAnalyzer<V : Value>(
current: StoreLoadFrame<V>, current: StoreLoadFrame<V>,
handler: StoreLoadFrame<V>, handler: StoreLoadFrame<V>,
) { ) {
if (insnType == AbstractInsnNode.LABEL || insnType == AbstractInsnNode.LINE || insnType == AbstractInsnNode.FRAME) { if (insnType == AbstractInsnNode.LABEL ||
mergeControlFlowEdge(insnIndex + 1, currentlyAnalyzing) insnType == AbstractInsnNode.LINE ||
insnType == AbstractInsnNode.FRAME ||
insnOpcode == Opcodes.NOP
) {
visitNopInsn(insnNode, currentlyAnalyzing, insnIndex)
} else { } else {
current.init(currentlyAnalyzing).execute(insnNode, interpreter) current.init(currentlyAnalyzing).execute(insnNode, interpreter)
visitMeaningfulInstruction(insnNode, insnType, insnOpcode, current, insnIndex) visitMeaningfulInstruction(insnNode, insnType, insnOpcode, current, insnIndex)