backend: don't generate the same string literal twice
This commit is contained in:
committed by
SvyatoslavScherbina
parent
cc1b2b9684
commit
e5d4dc932b
+1
-1
@@ -360,7 +360,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
||||
IrConstKind.Int -> return LLVMConstInt(LLVMInt32Type(), (value.value as Int).toLong(), 1)
|
||||
IrConstKind.Long -> return LLVMConstInt(LLVMInt64Type(), value.value as Long, 1)
|
||||
IrConstKind.String ->
|
||||
return context.staticData.createStringLiteral(value as IrConst<String>).getLlvmValue()
|
||||
return context.staticData.kotlinStringLiteral(value as IrConst<String>).getLlvmValue()
|
||||
IrConstKind.Float -> return LLVMConstRealOfString(LLVMFloatType(), (value.value as Float).toString())
|
||||
IrConstKind.Double -> return LLVMConstRealOfString(LLVMDoubleType(), (value.value as Double).toString())
|
||||
}
|
||||
|
||||
+6
@@ -1,6 +1,7 @@
|
||||
package org.jetbrains.kotlin.backend.konan.llvm
|
||||
|
||||
import llvm.*
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConst
|
||||
|
||||
/**
|
||||
* Provides utilities to create static data.
|
||||
@@ -108,4 +109,9 @@ internal class StaticData(override val context: Context): ContextUtils {
|
||||
|
||||
return global
|
||||
}
|
||||
|
||||
private val stringLiterals = mutableMapOf<String, ConstPointer>()
|
||||
|
||||
fun kotlinStringLiteral(value: IrConst<String>) =
|
||||
stringLiterals.getOrPut(value.value) { createKotlinStringLiteral(value) }
|
||||
}
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ private fun StaticData.staticContainerHeader(): Struct {
|
||||
return Struct(runtime.containerHeaderType, Int32(CONTAINER_TAG_NOCOUNT))
|
||||
}
|
||||
|
||||
internal fun StaticData.createStringLiteral(value: IrConst<String>): ConstPointer {
|
||||
internal fun StaticData.createKotlinStringLiteral(value: IrConst<String>): ConstPointer {
|
||||
val base64Str = value.value.globalHashBase64
|
||||
val valueBytes = value.value.toByteArray(Charsets.UTF_8)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user