Minor. Cleanup codegen.optimization package
This commit is contained in:
+1
-1
@@ -28,4 +28,4 @@ class MandatoryMethodTransformer : MethodTransformer() {
|
|||||||
labelNormalization.transform(internalClassName, methodNode)
|
labelNormalization.transform(internalClassName, methodNode)
|
||||||
fixStack.transform(internalClassName, methodNode)
|
fixStack.transform(internalClassName, methodNode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -208,7 +208,7 @@ open class MethodAnalyzer<V : Value>(
|
|||||||
|
|
||||||
private fun mergeControlFlowEdge(insn: Int, frame: Frame<V>) {
|
private fun mergeControlFlowEdge(insn: Int, frame: Frame<V>) {
|
||||||
val oldFrame = frames[insn]
|
val oldFrame = frames[insn]
|
||||||
var changes: Boolean
|
val changes: Boolean
|
||||||
|
|
||||||
if (oldFrame == null) {
|
if (oldFrame == null) {
|
||||||
frames[insn] = newFrame(frame)
|
frames[insn] = newFrame(frame)
|
||||||
@@ -223,4 +223,4 @@ open class MethodAnalyzer<V : Value>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-4
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.codegen.optimization.fixStack
|
package org.jetbrains.kotlin.codegen.optimization.fixStack
|
||||||
|
|
||||||
import com.intellij.util.SmartList
|
|
||||||
import com.intellij.util.containers.Stack
|
import com.intellij.util.containers.Stack
|
||||||
import org.jetbrains.kotlin.codegen.inline.InlineCodegenUtil
|
import org.jetbrains.kotlin.codegen.inline.InlineCodegenUtil
|
||||||
import org.jetbrains.kotlin.codegen.optimization.common.MethodAnalyzer
|
import org.jetbrains.kotlin.codegen.optimization.common.MethodAnalyzer
|
||||||
@@ -26,11 +25,9 @@ import org.jetbrains.org.objectweb.asm.Opcodes
|
|||||||
import org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode
|
import org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode
|
||||||
import org.jetbrains.org.objectweb.asm.tree.JumpInsnNode
|
import org.jetbrains.org.objectweb.asm.tree.JumpInsnNode
|
||||||
import org.jetbrains.org.objectweb.asm.tree.MethodNode
|
import org.jetbrains.org.objectweb.asm.tree.MethodNode
|
||||||
import org.jetbrains.org.objectweb.asm.tree.TryCatchBlockNode
|
|
||||||
import org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue
|
import org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue
|
||||||
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 java.util.*
|
|
||||||
|
|
||||||
internal class FixStackAnalyzer(
|
internal class FixStackAnalyzer(
|
||||||
owner: String,
|
owner: String,
|
||||||
@@ -159,4 +156,4 @@ internal class FixStackAnalyzer(
|
|||||||
private fun FixStackFrame.executeSaveStackBeforeTry(insn: AbstractInsnNode) {
|
private fun FixStackFrame.executeSaveStackBeforeTry(insn: AbstractInsnNode) {
|
||||||
saveStackAndClear(insn)
|
saveStackAndClear(insn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-7
@@ -23,13 +23,13 @@ import org.jetbrains.kotlin.codegen.inline.InlineCodegenUtil
|
|||||||
import org.jetbrains.kotlin.codegen.optimization.common.InsnSequence
|
import org.jetbrains.kotlin.codegen.optimization.common.InsnSequence
|
||||||
import org.jetbrains.kotlin.codegen.optimization.common.findPreviousOrNull
|
import org.jetbrains.kotlin.codegen.optimization.common.findPreviousOrNull
|
||||||
import org.jetbrains.kotlin.codegen.optimization.common.hasOpcode
|
import org.jetbrains.kotlin.codegen.optimization.common.hasOpcode
|
||||||
import org.jetbrains.kotlin.codegen.optimization.fixStack.forEachPseudoInsn
|
|
||||||
import org.jetbrains.kotlin.codegen.pseudoInsns.PseudoInsn
|
import org.jetbrains.kotlin.codegen.pseudoInsns.PseudoInsn
|
||||||
import org.jetbrains.kotlin.codegen.pseudoInsns.parsePseudoInsnOrNull
|
import org.jetbrains.kotlin.codegen.pseudoInsns.parsePseudoInsnOrNull
|
||||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
import org.jetbrains.org.objectweb.asm.Opcodes
|
||||||
import org.jetbrains.org.objectweb.asm.tree.*
|
import org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode
|
||||||
import java.util.*
|
import org.jetbrains.org.objectweb.asm.tree.JumpInsnNode
|
||||||
import kotlin.properties.Delegates
|
import org.jetbrains.org.objectweb.asm.tree.LabelNode
|
||||||
|
import org.jetbrains.org.objectweb.asm.tree.MethodNode
|
||||||
|
|
||||||
internal class FixStackContext(val methodNode: MethodNode) {
|
internal class FixStackContext(val methodNode: MethodNode) {
|
||||||
val breakContinueGotoNodes = linkedSetOf<JumpInsnNode>()
|
val breakContinueGotoNodes = linkedSetOf<JumpInsnNode>()
|
||||||
@@ -103,7 +103,7 @@ internal class FixStackContext(val methodNode: MethodNode) {
|
|||||||
if (restoreLabel !is LabelNode) {
|
if (restoreLabel !is LabelNode) {
|
||||||
throw AssertionError("${indexOf(insnNode)}: restore should be preceded by a catch block label")
|
throw AssertionError("${indexOf(insnNode)}: restore should be preceded by a catch block label")
|
||||||
}
|
}
|
||||||
val saveNodes = findMatchingSaveNodes(insnNode, restoreLabel)
|
val saveNodes = findMatchingSaveNodes(restoreLabel)
|
||||||
if (saveNodes.isEmpty()) {
|
if (saveNodes.isEmpty()) {
|
||||||
throw AssertionError("${indexOf(insnNode)}: in handler ${indexOf(restoreLabel)} restore is not matched with save")
|
throw AssertionError("${indexOf(insnNode)}: in handler ${indexOf(restoreLabel)} restore is not matched with save")
|
||||||
}
|
}
|
||||||
@@ -115,7 +115,7 @@ internal class FixStackContext(val methodNode: MethodNode) {
|
|||||||
restoreStackMarkersForSaveMarker.getOrPut(saveNode, { SmartList<AbstractInsnNode>() }).add(insnNode)
|
restoreStackMarkersForSaveMarker.getOrPut(saveNode, { SmartList<AbstractInsnNode>() }).add(insnNode)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun findMatchingSaveNodes(insnNode: AbstractInsnNode, restoreLabel: LabelNode): List<AbstractInsnNode> {
|
private fun findMatchingSaveNodes(restoreLabel: LabelNode): List<AbstractInsnNode> {
|
||||||
val saveNodes = SmartHashSet<AbstractInsnNode>()
|
val saveNodes = SmartHashSet<AbstractInsnNode>()
|
||||||
methodNode.tryCatchBlocks.forEach { tcb ->
|
methodNode.tryCatchBlocks.forEach { tcb ->
|
||||||
if (restoreLabel == tcb.start || restoreLabel == tcb.handler) {
|
if (restoreLabel == tcb.start || restoreLabel == tcb.handler) {
|
||||||
@@ -139,4 +139,4 @@ internal class FixStackContext(val methodNode: MethodNode) {
|
|||||||
saveStackNodesForTryStartLabel.isNotEmpty() ||
|
saveStackNodesForTryStartLabel.isNotEmpty() ||
|
||||||
openingInlineMethodMarker.isNotEmpty()
|
openingInlineMethodMarker.isNotEmpty()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -94,4 +94,4 @@ internal class LocalVariablesManager(val context: FixStackContext, val methodNod
|
|||||||
updateMaxLocals(returnValueIndex + returnValue.size)
|
updateMaxLocals(returnValueIndex + returnValue.size)
|
||||||
return returnValueIndex
|
return returnValueIndex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-25
@@ -16,41 +16,18 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.codegen.optimization.fixStack
|
package org.jetbrains.kotlin.codegen.optimization.fixStack
|
||||||
|
|
||||||
import org.jetbrains.kotlin.codegen.inline.InlineCodegenUtil
|
|
||||||
import org.jetbrains.kotlin.codegen.optimization.common.InsnSequence
|
|
||||||
import org.jetbrains.kotlin.codegen.pseudoInsns.PseudoInsn
|
|
||||||
import org.jetbrains.kotlin.codegen.pseudoInsns.parsePseudoInsnOrNull
|
|
||||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
import org.jetbrains.org.objectweb.asm.Opcodes
|
||||||
import org.jetbrains.org.objectweb.asm.tree.*
|
import org.jetbrains.org.objectweb.asm.tree.*
|
||||||
import org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue
|
import org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue
|
||||||
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.Value
|
import org.jetbrains.org.objectweb.asm.tree.analysis.Value
|
||||||
|
|
||||||
inline fun InsnList.forEachPseudoInsn(block: (PseudoInsn, AbstractInsnNode) -> Unit) {
|
|
||||||
InsnSequence(this).forEach { insn ->
|
|
||||||
parsePseudoInsnOrNull(insn)?.let { block(it, insn) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline fun InsnList.forEachInlineMarker(block: (String, MethodInsnNode) -> Unit) {
|
|
||||||
InsnSequence(this).forEach { insn ->
|
|
||||||
if (InlineCodegenUtil.isInlineMarker(insn)) {
|
|
||||||
val methodInsnNode = insn as MethodInsnNode
|
|
||||||
block(methodInsnNode.name, methodInsnNode)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <V : Value> Frame<V>.top(): V? =
|
fun <V : Value> Frame<V>.top(): V? =
|
||||||
peek(0)
|
peek(0)
|
||||||
|
|
||||||
fun <V : Value> Frame<V>.peek(offset: Int): V? =
|
fun <V : Value> Frame<V>.peek(offset: Int): V? =
|
||||||
if (stackSize >= offset) getStack(stackSize - offset - 1) else null
|
if (stackSize >= offset) getStack(stackSize - offset - 1) else null
|
||||||
|
|
||||||
fun MethodNode.updateMaxLocals(newMaxLocals: Int) {
|
|
||||||
maxLocals = Math.max(maxLocals, newMaxLocals)
|
|
||||||
}
|
|
||||||
|
|
||||||
class SavedStackDescriptor(
|
class SavedStackDescriptor(
|
||||||
val savedValues: List<BasicValue>,
|
val savedValues: List<BasicValue>,
|
||||||
val firstLocalVarIndex: Int
|
val firstLocalVarIndex: Int
|
||||||
@@ -64,7 +41,6 @@ class SavedStackDescriptor(
|
|||||||
fun isNotEmpty(): Boolean = savedValues.isNotEmpty()
|
fun isNotEmpty(): Boolean = savedValues.isNotEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun saveStack(methodNode: MethodNode, nodeToReplace: AbstractInsnNode, savedStackDescriptor: SavedStackDescriptor,
|
fun saveStack(methodNode: MethodNode, nodeToReplace: AbstractInsnNode, savedStackDescriptor: SavedStackDescriptor,
|
||||||
restoreImmediately: Boolean) {
|
restoreImmediately: Boolean) {
|
||||||
with(methodNode.instructions) {
|
with(methodNode.instructions) {
|
||||||
@@ -148,4 +124,3 @@ fun replaceMarkerWithPops(methodNode: MethodNode, node: AbstractInsnNode, expect
|
|||||||
remove(node)
|
remove(node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user