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.lower.CrIrType
|
||||
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.codegen.*
|
||||
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
|
||||
// const_0 and const_1 in the generated java bytecode.
|
||||
if (isNegation(condition, classCodegen.context)) {
|
||||
condition = negationArgument(condition as IrCall)
|
||||
condition = (condition as IrCall).dispatchReceiver!!
|
||||
jumpIfFalse = !jumpIfFalse
|
||||
}
|
||||
|
||||
|
||||
+5
-18
@@ -34,19 +34,9 @@ internal val jvmBuiltinOptimizationLoweringPhase = makeIrFilePhase(
|
||||
class JvmBuiltinOptimizationLowering(val context: JvmBackendContext) : FileLoweringPass {
|
||||
|
||||
companion object {
|
||||
fun isNegation(expression: IrExpression, context: JvmBackendContext): Boolean {
|
||||
// TODO: there should be only one representation of the 'not' operator.
|
||||
return expression is IrCall &&
|
||||
(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)!!
|
||||
}
|
||||
fun isNegation(expression: IrExpression, context: JvmBackendContext): Boolean =
|
||||
expression is IrCall &&
|
||||
context.state.intrinsics.getIntrinsic(expression.symbol.descriptor) is Not
|
||||
}
|
||||
|
||||
private fun hasNoSideEffectsForNullCompare(expression: IrExpression): Boolean {
|
||||
@@ -80,11 +70,8 @@ class JvmBuiltinOptimizationLowering(val context: JvmBackendContext) : FileLower
|
||||
irFile.transformChildrenVoid(object : IrElementTransformerVoid() {
|
||||
override fun visitCall(expression: IrCall): IrExpression {
|
||||
expression.transformChildrenVoid(this)
|
||||
return if (isNegation(expression, context) && isNegation(negationArgument(expression), context)) {
|
||||
// TODO: This lowering is currently JvmBackend specific because there are multiple
|
||||
// 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)
|
||||
return if (isNegation(expression, context) && isNegation(expression.dispatchReceiver!!, context)) {
|
||||
(expression.dispatchReceiver as IrCall).dispatchReceiver!!
|
||||
} else if (isNullCheckOfPrimitiveTypeValue(expression, context)) {
|
||||
val left = expression.getValueArgument(0)!!
|
||||
val nonNullArgument = if (left.isNullConst()) expression.getValueArgument(1)!! else left
|
||||
|
||||
Reference in New Issue
Block a user