Remove hack from JvmBuiltinOptimizationLowering related to booleanNotSymbol
This commit is contained in:
committed by
Anton Bannykh
parent
a382956c19
commit
fff22d9372
+1
-2
@@ -11,7 +11,6 @@ import org.jetbrains.kotlin.backend.jvm.intrinsics.IrIntrinsicFunction
|
|||||||
import org.jetbrains.kotlin.backend.jvm.intrinsics.IrIntrinsicMethods
|
import org.jetbrains.kotlin.backend.jvm.intrinsics.IrIntrinsicMethods
|
||||||
import org.jetbrains.kotlin.backend.jvm.lower.CrIrType
|
import org.jetbrains.kotlin.backend.jvm.lower.CrIrType
|
||||||
import org.jetbrains.kotlin.backend.jvm.lower.JvmBuiltinOptimizationLowering.Companion.isNegation
|
import org.jetbrains.kotlin.backend.jvm.lower.JvmBuiltinOptimizationLowering.Companion.isNegation
|
||||||
import org.jetbrains.kotlin.backend.jvm.lower.JvmBuiltinOptimizationLowering.Companion.negationArgument
|
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.codegen.*
|
import org.jetbrains.kotlin.codegen.*
|
||||||
import org.jetbrains.kotlin.codegen.AsmUtil.*
|
import org.jetbrains.kotlin.codegen.AsmUtil.*
|
||||||
@@ -748,7 +747,7 @@ class ExpressionCodegen(
|
|||||||
// targets instead. This significantly cuts down the amount of branches and loads of
|
// targets instead. This significantly cuts down the amount of branches and loads of
|
||||||
// const_0 and const_1 in the generated java bytecode.
|
// const_0 and const_1 in the generated java bytecode.
|
||||||
if (isNegation(condition, classCodegen.context)) {
|
if (isNegation(condition, classCodegen.context)) {
|
||||||
condition = negationArgument(condition as IrCall)
|
condition = (condition as IrCall).dispatchReceiver!!
|
||||||
jumpIfFalse = !jumpIfFalse
|
jumpIfFalse = !jumpIfFalse
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-18
@@ -34,19 +34,9 @@ internal val jvmBuiltinOptimizationLoweringPhase = makeIrFilePhase(
|
|||||||
class JvmBuiltinOptimizationLowering(val context: JvmBackendContext) : FileLoweringPass {
|
class JvmBuiltinOptimizationLowering(val context: JvmBackendContext) : FileLoweringPass {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun isNegation(expression: IrExpression, context: JvmBackendContext): Boolean {
|
fun isNegation(expression: IrExpression, context: JvmBackendContext): Boolean =
|
||||||
// TODO: there should be only one representation of the 'not' operator.
|
expression is IrCall &&
|
||||||
return expression is IrCall &&
|
context.state.intrinsics.getIntrinsic(expression.symbol.descriptor) is Not
|
||||||
(expression.symbol == context.irBuiltIns.booleanNotSymbol ||
|
|
||||||
context.state.intrinsics.getIntrinsic(expression.symbol.descriptor) is Not)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun negationArgument(call: IrCall): IrExpression {
|
|
||||||
// TODO: there should be only one representation of the 'not' operator.
|
|
||||||
// Once there is only the IR definition the negation argument will
|
|
||||||
// always be a value argument and this method can be removed.
|
|
||||||
return call.dispatchReceiver ?: call.getValueArgument(0)!!
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun hasNoSideEffectsForNullCompare(expression: IrExpression): Boolean {
|
private fun hasNoSideEffectsForNullCompare(expression: IrExpression): Boolean {
|
||||||
@@ -80,11 +70,8 @@ class JvmBuiltinOptimizationLowering(val context: JvmBackendContext) : FileLower
|
|||||||
irFile.transformChildrenVoid(object : IrElementTransformerVoid() {
|
irFile.transformChildrenVoid(object : IrElementTransformerVoid() {
|
||||||
override fun visitCall(expression: IrCall): IrExpression {
|
override fun visitCall(expression: IrCall): IrExpression {
|
||||||
expression.transformChildrenVoid(this)
|
expression.transformChildrenVoid(this)
|
||||||
return if (isNegation(expression, context) && isNegation(negationArgument(expression), context)) {
|
return if (isNegation(expression, context) && isNegation(expression.dispatchReceiver!!, context)) {
|
||||||
// TODO: This lowering is currently JvmBackend specific because there are multiple
|
(expression.dispatchReceiver as IrCall).dispatchReceiver!!
|
||||||
// definitions of the boolean 'not' operator. Once there is only the irBuiltins
|
|
||||||
// definition this lowering could be shared with other backends.
|
|
||||||
negationArgument(negationArgument(expression) as IrCall)
|
|
||||||
} else if (isNullCheckOfPrimitiveTypeValue(expression, context)) {
|
} else if (isNullCheckOfPrimitiveTypeValue(expression, context)) {
|
||||||
val left = expression.getValueArgument(0)!!
|
val left = expression.getValueArgument(0)!!
|
||||||
val nonNullArgument = if (left.isNullConst()) expression.getValueArgument(1)!! else left
|
val nonNullArgument = if (left.isNullConst()) expression.getValueArgument(1)!! else left
|
||||||
|
|||||||
Reference in New Issue
Block a user