[WASM] Remove unnecessary boxing/unboxing
This commit is contained in:
+3
-1
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.backend.common.lower.AbstractValueUsageTransformer
|
|||||||
import org.jetbrains.kotlin.backend.common.pop
|
import org.jetbrains.kotlin.backend.common.pop
|
||||||
import org.jetbrains.kotlin.backend.common.push
|
import org.jetbrains.kotlin.backend.common.push
|
||||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||||
|
import org.jetbrains.kotlin.ir.IrStatement
|
||||||
import org.jetbrains.kotlin.ir.backend.js.JsCommonBackendContext
|
import org.jetbrains.kotlin.ir.backend.js.JsCommonBackendContext
|
||||||
import org.jetbrains.kotlin.ir.backend.js.ir.JsIrBuilder
|
import org.jetbrains.kotlin.ir.backend.js.ir.JsIrBuilder
|
||||||
import org.jetbrains.kotlin.ir.backend.js.utils.realOverrideTarget
|
import org.jetbrains.kotlin.ir.backend.js.utils.realOverrideTarget
|
||||||
@@ -165,6 +166,8 @@ class AutoboxingTransformer(context: JsCommonBackendContext) : AbstractValueUsag
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (expectedType.isUnit()) return this
|
||||||
|
|
||||||
val actualInlinedClass = icUtils.getInlinedClass(actualType)
|
val actualInlinedClass = icUtils.getInlinedClass(actualType)
|
||||||
val expectedInlinedClass = icUtils.getInlinedClass(expectedType)
|
val expectedInlinedClass = icUtils.getInlinedClass(expectedType)
|
||||||
|
|
||||||
@@ -246,7 +249,6 @@ class AutoboxingTransformer(context: JsCommonBackendContext) : AbstractValueUsag
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private tailrec fun IrExpression.isGetUnit(irBuiltIns: IrBuiltIns): Boolean =
|
private tailrec fun IrExpression.isGetUnit(irBuiltIns: IrBuiltIns): Boolean =
|
||||||
|
|||||||
@@ -118,10 +118,24 @@ class WasmSymbols(
|
|||||||
|
|
||||||
val wasmUnreachable = getInternalFunction("wasm_unreachable")
|
val wasmUnreachable = getInternalFunction("wasm_unreachable")
|
||||||
|
|
||||||
val consumeAnyIntoVoid = getInternalFunction("consumeAnyIntoVoid")
|
|
||||||
val voidClass = getIrClass(FqName("kotlin.wasm.internal.Void"))
|
val voidClass = getIrClass(FqName("kotlin.wasm.internal.Void"))
|
||||||
val voidType by lazy { voidClass.defaultType }
|
val voidType by lazy { voidClass.defaultType }
|
||||||
|
|
||||||
|
private val consumeAnyIntoVoid = getInternalFunction("consumeAnyIntoVoid")
|
||||||
|
private val consumePrimitiveIntoVoid = mapOf(
|
||||||
|
context.irBuiltIns.booleanType to getInternalFunction("consumeBooleanIntoVoid"),
|
||||||
|
context.irBuiltIns.byteType to getInternalFunction("consumeByteIntoVoid"),
|
||||||
|
context.irBuiltIns.shortType to getInternalFunction("consumeShortIntoVoid"),
|
||||||
|
context.irBuiltIns.charType to getInternalFunction("consumeCharIntoVoid"),
|
||||||
|
context.irBuiltIns.intType to getInternalFunction("consumeIntIntoVoid"),
|
||||||
|
context.irBuiltIns.longType to getInternalFunction("consumeLongIntoVoid"),
|
||||||
|
context.irBuiltIns.floatType to getInternalFunction("consumeFloatIntoVoid"),
|
||||||
|
context.irBuiltIns.doubleType to getInternalFunction("consumeDoubleIntoVoid")
|
||||||
|
)
|
||||||
|
|
||||||
|
fun findVoidConsumer(type: IrType): IrSimpleFunctionSymbol =
|
||||||
|
consumePrimitiveIntoVoid[type] ?: consumeAnyIntoVoid
|
||||||
|
|
||||||
val equalityFunctions = mapOf(
|
val equalityFunctions = mapOf(
|
||||||
context.irBuiltIns.booleanType to getInternalFunction("wasm_i32_eq"),
|
context.irBuiltIns.booleanType to getInternalFunction("wasm_i32_eq"),
|
||||||
context.irBuiltIns.byteType to getInternalFunction("wasm_i32_eq"),
|
context.irBuiltIns.byteType to getInternalFunction("wasm_i32_eq"),
|
||||||
|
|||||||
+1
-1
@@ -134,7 +134,7 @@ class UnitToVoidLowering(val context: WasmBackendContext) : FileLoweringPass, Ab
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return IrCallImpl(expr.startOffset, expr.endOffset, symbols.voidType, symbols.consumeAnyIntoVoid, 0, 1).apply {
|
return IrCallImpl(expr.startOffset, expr.endOffset, symbols.voidType, symbols.findVoidConsumer(expr.type), 0, 1).apply {
|
||||||
putValueArgument(0, expr)
|
putValueArgument(0, expr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -237,7 +237,7 @@ class WasmBaseTypeOperatorTransformer(val context: WasmBackendContext) : IrEleme
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (toType == symbols.voidType) {
|
if (toType == symbols.voidType) {
|
||||||
return builder.irCall(symbols.consumeAnyIntoVoid).apply {
|
return builder.irCall(symbols.findVoidConsumer(value.type)).apply {
|
||||||
putValueArgument(0, value)
|
putValueArgument(0, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,6 +82,38 @@ internal class Void private constructor()
|
|||||||
internal fun consumeAnyIntoVoid(a: Any?): Void =
|
internal fun consumeAnyIntoVoid(a: Any?): Void =
|
||||||
implementedAsIntrinsic
|
implementedAsIntrinsic
|
||||||
|
|
||||||
|
@WasmOp(WasmOp.DROP)
|
||||||
|
internal fun consumeBooleanIntoVoid(a: Boolean): Void =
|
||||||
|
implementedAsIntrinsic
|
||||||
|
|
||||||
|
@WasmOp(WasmOp.DROP)
|
||||||
|
internal fun consumeByteIntoVoid(a: Byte): Void =
|
||||||
|
implementedAsIntrinsic
|
||||||
|
|
||||||
|
@WasmOp(WasmOp.DROP)
|
||||||
|
internal fun consumeShortIntoVoid(a: Short): Void =
|
||||||
|
implementedAsIntrinsic
|
||||||
|
|
||||||
|
@WasmOp(WasmOp.DROP)
|
||||||
|
internal fun consumeCharIntoVoid(a: Char): Void =
|
||||||
|
implementedAsIntrinsic
|
||||||
|
|
||||||
|
@WasmOp(WasmOp.DROP)
|
||||||
|
internal fun consumeIntIntoVoid(a: Int): Void =
|
||||||
|
implementedAsIntrinsic
|
||||||
|
|
||||||
|
@WasmOp(WasmOp.DROP)
|
||||||
|
internal fun consumeLongIntoVoid(a: Long): Void =
|
||||||
|
implementedAsIntrinsic
|
||||||
|
|
||||||
|
@WasmOp(WasmOp.DROP)
|
||||||
|
internal fun consumeFloatIntoVoid(a: Float): Void =
|
||||||
|
implementedAsIntrinsic
|
||||||
|
|
||||||
|
@WasmOp(WasmOp.DROP)
|
||||||
|
internal fun consumeDoubleIntoVoid(a: Double): Void =
|
||||||
|
implementedAsIntrinsic
|
||||||
|
|
||||||
@ExcludedFromCodegen
|
@ExcludedFromCodegen
|
||||||
internal fun stringGetPoolSize(): Int =
|
internal fun stringGetPoolSize(): Int =
|
||||||
implementedAsIntrinsic
|
implementedAsIntrinsic
|
||||||
|
|||||||
Reference in New Issue
Block a user