Get rid of InstructionsAndFrames.kt
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.codegen.inline
|
||||
|
||||
import org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode
|
||||
import org.jetbrains.org.objectweb.asm.tree.InsnList
|
||||
import org.jetbrains.org.objectweb.asm.tree.analysis.Frame
|
||||
import org.jetbrains.org.objectweb.asm.tree.analysis.SourceValue
|
||||
|
||||
class InstructionsAndFrames(val frames: Array<Frame<SourceValue>>, ins: InsnList) {
|
||||
|
||||
val indexes = (0..ins.size() - 1).associate { Pair(ins.get(it), it) }
|
||||
|
||||
operator fun get(node: AbstractInsnNode): Frame<SourceValue>? = frames[indexes[node]!!]
|
||||
|
||||
}
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.codegen.inline;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.containers.SmartHashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.codegen.ClosureCodegen;
|
||||
@@ -26,6 +25,7 @@ import org.jetbrains.kotlin.codegen.StackValue;
|
||||
import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicMethods;
|
||||
import org.jetbrains.kotlin.codegen.optimization.MandatoryMethodTransformer;
|
||||
import org.jetbrains.kotlin.codegen.state.JetTypeMapper;
|
||||
import org.jetbrains.kotlin.utils.SmartSet;
|
||||
import org.jetbrains.org.objectweb.asm.Label;
|
||||
import org.jetbrains.org.objectweb.asm.MethodVisitor;
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes;
|
||||
@@ -428,9 +428,9 @@ public class MethodInliner {
|
||||
catch (AnalyzerException e) {
|
||||
throw wrapException(e, node, "couldn't inline method call");
|
||||
}
|
||||
Set<AbstractInsnNode> toDelete = new SmartHashSet<AbstractInsnNode>();
|
||||
InstructionsAndFrames instructionsAndFrames = new InstructionsAndFrames(sources, node.instructions);
|
||||
AbstractInsnNode cur = node.instructions.getFirst();
|
||||
Set<AbstractInsnNode> toDelete = SmartSet.create();
|
||||
InsnList instructions = node.instructions;
|
||||
AbstractInsnNode cur = instructions.getFirst();
|
||||
int index = 0;
|
||||
|
||||
boolean awaitClassReification = false;
|
||||
@@ -466,7 +466,7 @@ public class MethodInliner {
|
||||
AbstractInsnNode insnNode = MethodInlinerUtilKt.singleOrNullInsn(sourceValue);
|
||||
if (insnNode != null) {
|
||||
lambdaInfo = MethodInlinerUtilKt.getLambdaIfExistsAndMarkInstructions(
|
||||
this, insnNode, frame, instructionsAndFrames, toDelete, true
|
||||
this, insnNode, frame, true, instructions, sources, toDelete
|
||||
);
|
||||
}
|
||||
|
||||
@@ -481,7 +481,7 @@ public class MethodInliner {
|
||||
AbstractInsnNode insnNode = MethodInlinerUtilKt.singleOrNullInsn(sourceValue);
|
||||
if (insnNode != null) {
|
||||
LambdaInfo lambdaInfo = MethodInlinerUtilKt.getLambdaIfExistsAndMarkInstructions(
|
||||
this, insnNode, frame, instructionsAndFrames, toDelete, false
|
||||
this, insnNode, frame, false, instructions, sources, toDelete
|
||||
);
|
||||
if (lambdaInfo != null) {
|
||||
lambdaMapping.put(offset, lambdaInfo);
|
||||
@@ -523,13 +523,13 @@ public class MethodInliner {
|
||||
//it may occurs that interval for default handler starts before catch start label, so this label seems as dead,
|
||||
//but as result all this labels will be merged into one (see KT-5863)
|
||||
} else {
|
||||
node.instructions.remove(prevNode);
|
||||
toDelete.add(prevNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (AbstractInsnNode insnNode : toDelete) {
|
||||
node.instructions.remove(insnNode);
|
||||
instructions.remove(insnNode);
|
||||
}
|
||||
|
||||
//clean dead try/catch blocks
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.codegen.inline
|
||||
import org.jetbrains.kotlin.codegen.optimization.common.InsnSequence
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
||||
import org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode
|
||||
import org.jetbrains.org.objectweb.asm.tree.InsnList
|
||||
import org.jetbrains.org.objectweb.asm.tree.VarInsnNode
|
||||
import org.jetbrains.org.objectweb.asm.tree.analysis.Frame
|
||||
import org.jetbrains.org.objectweb.asm.tree.analysis.SourceValue
|
||||
@@ -27,9 +28,11 @@ import org.jetbrains.org.objectweb.asm.tree.analysis.SourceValue
|
||||
fun MethodInliner.getLambdaIfExistsAndMarkInstructions(
|
||||
insnNode: AbstractInsnNode,
|
||||
localFrame: Frame<SourceValue>,
|
||||
insAndFrames: InstructionsAndFrames,
|
||||
toDelete: MutableSet<AbstractInsnNode>,
|
||||
processSwap: Boolean): LambdaInfo? {
|
||||
processSwap: Boolean,
|
||||
insnList: InsnList,
|
||||
frames: Array<Frame<SourceValue>?>,
|
||||
toDelete: MutableSet<AbstractInsnNode>
|
||||
): LambdaInfo? {
|
||||
|
||||
val processingInsnNode = if (processSwap && insnNode.opcode == Opcodes.SWAP) InlineCodegenUtil.getPrevMeaningful(insnNode) else insnNode
|
||||
|
||||
@@ -40,12 +43,12 @@ fun MethodInliner.getLambdaIfExistsAndMarkInstructions(
|
||||
val local = localFrame.getLocal(varIndex)
|
||||
val storeIns = local.singleOrNullInsn()
|
||||
if (storeIns is VarInsnNode && storeIns.getOpcode() == Opcodes.ASTORE) {
|
||||
val frame = insAndFrames[storeIns]
|
||||
val frame = frames[insnList.indexOf(storeIns)]
|
||||
if (frame != null) {
|
||||
val topOfStack = frame.getStack(frame.stackSize - 1)
|
||||
val lambdaAload = topOfStack.singleOrNullInsn()
|
||||
if (lambdaAload != null) {
|
||||
lambdaInfo = getLambdaIfExistsAndMarkInstructions(lambdaAload, frame, insAndFrames, toDelete, processSwap)
|
||||
lambdaInfo = getLambdaIfExistsAndMarkInstructions(lambdaAload, frame, processSwap, insnList, frames, toDelete)
|
||||
if (lambdaInfo != null) {
|
||||
toDelete.add(storeIns)
|
||||
toDelete.add(lambdaAload)
|
||||
|
||||
Reference in New Issue
Block a user