Cache calculated LLVMRefs for IrType and external functions
This commit is contained in:
committed by
LepilkinaElena
parent
4e34b4fcc6
commit
64cb79ab7a
+3
-2
@@ -164,8 +164,9 @@ internal interface ContextUtils : RuntimeAware {
|
||||
assert(this.isReal)
|
||||
|
||||
return if (isExternal(this)) {
|
||||
context.llvm.externalFunction(this.symbolName, getLlvmFunctionType(this),
|
||||
origin = this.llvmSymbolOrigin)
|
||||
runtime.addedLLVMExternalFunctions.getOrPut(this) { context.llvm.externalFunction(this.symbolName, getLlvmFunctionType(this),
|
||||
origin = this.llvmSymbolOrigin) }
|
||||
|
||||
} else {
|
||||
context.llvmDeclarations.forFunctionOrNull(this)?.llvmFunction
|
||||
}
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ private fun RuntimeAware.getLlvmType(primitiveBinaryType: PrimitiveBinaryType?)
|
||||
}
|
||||
|
||||
internal fun RuntimeAware.getLLVMType(type: IrType): LLVMTypeRef =
|
||||
getLlvmType(type.computePrimitiveBinaryTypeOrNull())
|
||||
runtime.calculatedLLVMTypes.getOrPut(type) { getLlvmType(type.computePrimitiveBinaryTypeOrNull()) }
|
||||
|
||||
internal fun RuntimeAware.getLLVMType(type: DataFlowIR.Type) =
|
||||
getLlvmType(type.primitiveBinaryType)
|
||||
|
||||
+4
@@ -7,6 +7,8 @@ package org.jetbrains.kotlin.backend.konan.llvm
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
import llvm.*
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
|
||||
interface RuntimeAware {
|
||||
val runtime: Runtime
|
||||
@@ -14,6 +16,8 @@ interface RuntimeAware {
|
||||
|
||||
class Runtime(bitcodeFile: String) {
|
||||
val llvmModule: LLVMModuleRef = parseBitcodeFile(bitcodeFile)
|
||||
val calculatedLLVMTypes: MutableMap<IrType, LLVMTypeRef> = HashMap()
|
||||
val addedLLVMExternalFunctions: MutableMap<IrFunction, LLVMValueRef> = HashMap()
|
||||
|
||||
internal fun getStructTypeOrNull(name: String) = LLVMGetTypeByName(llvmModule, "struct.$name")
|
||||
internal fun getStructType(name: String) = getStructTypeOrNull(name)
|
||||
|
||||
Reference in New Issue
Block a user