JVM optimize out temporary variables in bytecode
This commit is contained in:
committed by
TeamCityServer
parent
bddfd086f6
commit
041773fd25
+10
-1
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.codegen.inline.ReifiedTypeInliner.Companion.putNeedC
|
||||
import org.jetbrains.kotlin.codegen.inline.ReifiedTypeInliner.OperationKind.AS
|
||||
import org.jetbrains.kotlin.codegen.inline.ReifiedTypeInliner.OperationKind.SAFE_AS
|
||||
import org.jetbrains.kotlin.codegen.intrinsics.TypeIntrinsics
|
||||
import org.jetbrains.kotlin.codegen.optimization.temporaryVals.addTemporaryValInitMarker
|
||||
import org.jetbrains.kotlin.codegen.pseudoInsns.fakeAlwaysFalseIfeq
|
||||
import org.jetbrains.kotlin.codegen.pseudoInsns.fixStackAndJump
|
||||
import org.jetbrains.kotlin.codegen.signature.BothSignatureWriter
|
||||
@@ -629,6 +630,9 @@ class ExpressionCodegen(
|
||||
initializer.markLineNumber(startOffset = true)
|
||||
value.materializeAt(varType, declaration.type)
|
||||
declaration.markLineNumber(startOffset = true)
|
||||
if (declaration.isTemporaryVal()) {
|
||||
mv.addTemporaryValInitMarker()
|
||||
}
|
||||
mv.store(index, varType)
|
||||
} else if (declaration.isVisibleInLVT) {
|
||||
pushDefaultValueOnStack(varType, mv)
|
||||
@@ -646,6 +650,11 @@ class ExpressionCodegen(
|
||||
return MaterialValue(this, type, expression.symbol.owner.realType)
|
||||
}
|
||||
|
||||
private fun IrValueDeclaration.isTemporaryVal() =
|
||||
this is IrVariable &&
|
||||
!this.isVar &&
|
||||
this.origin == IrDeclarationOrigin.IR_TEMPORARY_VARIABLE
|
||||
|
||||
internal fun genOrGetLocal(expression: IrExpression, type: Type, parameterType: IrType, data: BlockInfo): StackValue =
|
||||
if (expression is IrGetValue)
|
||||
StackValue.local(
|
||||
@@ -766,7 +775,7 @@ class ExpressionCodegen(
|
||||
val index = frameMap.getIndex(irSymbol)
|
||||
if (index >= 0)
|
||||
return index
|
||||
throw AssertionError("Non-mapped local declaration: $irSymbol\n in ${irFunction.dump()}")
|
||||
throw AssertionError("Non-mapped local declaration: ${irSymbol.owner.dump()}\n in ${irFunction.dump()}")
|
||||
}
|
||||
|
||||
private fun handlePlusMinus(expression: IrSetValue, value: IrExpression?, isMinus: Boolean): Boolean {
|
||||
|
||||
@@ -57,9 +57,8 @@ class IrCallImpl(
|
||||
valueArgumentsCount: Int = symbol.descriptor.valueParameters.size,
|
||||
origin: IrStatementOrigin? = null,
|
||||
superQualifierSymbol: IrClassSymbol? = null,
|
||||
) = IrCallImpl(
|
||||
startOffset, endOffset, type, symbol, typeArgumentsCount, valueArgumentsCount, origin, superQualifierSymbol
|
||||
)
|
||||
) =
|
||||
IrCallImpl(startOffset, endOffset, type, symbol, typeArgumentsCount, valueArgumentsCount, origin, superQualifierSymbol)
|
||||
|
||||
fun fromSymbolOwner(
|
||||
startOffset: Int,
|
||||
@@ -70,8 +69,24 @@ class IrCallImpl(
|
||||
valueArgumentsCount: Int = symbol.owner.valueParameters.size,
|
||||
origin: IrStatementOrigin? = null,
|
||||
superQualifierSymbol: IrClassSymbol? = null,
|
||||
) = IrCallImpl(
|
||||
startOffset, endOffset, type, symbol, typeArgumentsCount, valueArgumentsCount, origin, superQualifierSymbol
|
||||
)
|
||||
) =
|
||||
IrCallImpl(startOffset, endOffset, type, symbol, typeArgumentsCount, valueArgumentsCount, origin, superQualifierSymbol)
|
||||
|
||||
fun fromSymbolOwner(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
symbol: IrSimpleFunctionSymbol
|
||||
) =
|
||||
IrCallImpl(
|
||||
startOffset,
|
||||
endOffset,
|
||||
symbol.owner.returnType,
|
||||
symbol,
|
||||
typeArgumentsCount = symbol.owner.typeParameters.size,
|
||||
valueArgumentsCount = symbol.owner.valueParameters.size,
|
||||
origin = null,
|
||||
superQualifierSymbol = null
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user