[WASM] Remove unnecessary boxing/unboxing

This commit is contained in:
Igor Yakovlev
2022-10-13 16:30:40 +02:00
committed by teamcity
parent 0e16889f45
commit 8d8430cde7
5 changed files with 52 additions and 4 deletions
@@ -118,10 +118,24 @@ class WasmSymbols(
val wasmUnreachable = getInternalFunction("wasm_unreachable")
val consumeAnyIntoVoid = getInternalFunction("consumeAnyIntoVoid")
val voidClass = getIrClass(FqName("kotlin.wasm.internal.Void"))
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(
context.irBuiltIns.booleanType to getInternalFunction("wasm_i32_eq"),
context.irBuiltIns.byteType to getInternalFunction("wasm_i32_eq"),
@@ -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)
}
}
@@ -237,7 +237,7 @@ class WasmBaseTypeOperatorTransformer(val context: WasmBackendContext) : IrEleme
}
if (toType == symbols.voidType) {
return builder.irCall(symbols.consumeAnyIntoVoid).apply {
return builder.irCall(symbols.findVoidConsumer(value.type)).apply {
putValueArgument(0, value)
}
}