Added names to private functions and types
This commit is contained in:
committed by
Pavel Punegov
parent
0927dfd070
commit
b8340ead91
+3
-2
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.backend.konan.library.LinkData
|
|||||||
import org.jetbrains.kotlin.backend.konan.llvm.*
|
import org.jetbrains.kotlin.backend.konan.llvm.*
|
||||||
import org.jetbrains.kotlin.backend.konan.lower.DECLARATION_ORIGIN_BRIDGE_METHOD
|
import org.jetbrains.kotlin.backend.konan.lower.DECLARATION_ORIGIN_BRIDGE_METHOD
|
||||||
import org.jetbrains.kotlin.backend.konan.lower.bridgeTarget
|
import org.jetbrains.kotlin.backend.konan.lower.bridgeTarget
|
||||||
|
import org.jetbrains.kotlin.backend.konan.optimizations.DataFlowIR
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
||||||
@@ -279,8 +280,8 @@ internal class Context(config: KonanConfig) : KonanBackendContext(config) {
|
|||||||
var phase: KonanPhase? = null
|
var phase: KonanPhase? = null
|
||||||
var depth: Int = 0
|
var depth: Int = 0
|
||||||
|
|
||||||
lateinit var privateFunctions: List<IrFunction>
|
lateinit var privateFunctions: List<Pair<IrFunction, DataFlowIR.FunctionSymbol.Declared>>
|
||||||
lateinit var privateClasses: List<IrClass>
|
lateinit var privateClasses: List<Pair<IrClass, DataFlowIR.Type.Declared>>
|
||||||
|
|
||||||
// Cache used for source offset->(line,column) mapping.
|
// Cache used for source offset->(line,column) mapping.
|
||||||
val fileEntryCache = mutableMapOf<String, SourceManager.FileEntry>()
|
val fileEntryCache = mutableMapOf<String, SourceManager.FileEntry>()
|
||||||
|
|||||||
+3
-1
@@ -230,6 +230,7 @@ internal interface IrPrivateClassReference : IrClassReference {
|
|||||||
val moduleDescriptor: ModuleDescriptor
|
val moduleDescriptor: ModuleDescriptor
|
||||||
val totalClasses: Int
|
val totalClasses: Int
|
||||||
val classIndex: Int
|
val classIndex: Int
|
||||||
|
val dfgSymbol: DataFlowIR.Type.Declared
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class IrPrivateClassReferenceImpl(startOffset: Int,
|
internal class IrPrivateClassReferenceImpl(startOffset: Int,
|
||||||
@@ -239,7 +240,8 @@ internal class IrPrivateClassReferenceImpl(startOffset: Int,
|
|||||||
override val classType: KotlinType,
|
override val classType: KotlinType,
|
||||||
override val moduleDescriptor: ModuleDescriptor,
|
override val moduleDescriptor: ModuleDescriptor,
|
||||||
override val totalClasses: Int,
|
override val totalClasses: Int,
|
||||||
override val classIndex: Int
|
override val classIndex: Int,
|
||||||
|
override val dfgSymbol: DataFlowIR.Type.Declared
|
||||||
) : IrPrivateClassReference,
|
) : IrPrivateClassReference,
|
||||||
IrTerminalDeclarationReferenceBase<IrClassifierSymbol, ClassifierDescriptor>(
|
IrTerminalDeclarationReferenceBase<IrClassifierSymbol, ClassifierDescriptor>(
|
||||||
startOffset, endOffset, type,
|
startOffset, endOffset, type,
|
||||||
|
|||||||
+2
-2
@@ -300,9 +300,9 @@ internal val ClassDescriptor.objectInstanceShadowFieldSymbolName: String
|
|||||||
internal val ClassDescriptor.typeInfoHasVtableAttached: Boolean
|
internal val ClassDescriptor.typeInfoHasVtableAttached: Boolean
|
||||||
get() = !this.isAbstract() && !this.isExternalObjCClass()
|
get() = !this.isAbstract() && !this.isExternalObjCClass()
|
||||||
|
|
||||||
internal fun ModuleDescriptor.privateFunctionSymbolName(index: Int) = "private_functions_${name.asString()}_$index"
|
internal fun ModuleDescriptor.privateFunctionSymbolName(index: Int, functionName: String?) = "private_functions_${name.asString()}_${functionName}_$index"
|
||||||
|
|
||||||
internal fun ModuleDescriptor.privateClassSymbolName(index: Int) = "private_classes_${name.asString()}_$index"
|
internal fun ModuleDescriptor.privateClassSymbolName(index: Int, className: String?) = "private_classes_${name.asString()}_${className}_$index"
|
||||||
|
|
||||||
internal val String.moduleConstructorName
|
internal val String.moduleConstructorName
|
||||||
get() = "_Konan_init_${this}"
|
get() = "_Konan_init_${this}"
|
||||||
|
|||||||
+8
-8
@@ -94,12 +94,12 @@ internal fun emitLLVM(context: Context) {
|
|||||||
|
|
||||||
val privateFunctions = moduleDFG!!.symbolTable.getPrivateFunctionsTableForExport()
|
val privateFunctions = moduleDFG!!.symbolTable.getPrivateFunctionsTableForExport()
|
||||||
privateFunctions.forEachIndexed { index, it ->
|
privateFunctions.forEachIndexed { index, it ->
|
||||||
val function = codegenVisitor.codegen.llvmFunction(it)
|
val function = codegenVisitor.codegen.llvmFunction(it.first)
|
||||||
LLVMAddAlias(
|
LLVMAddAlias(
|
||||||
context.llvmModule,
|
context.llvmModule,
|
||||||
function.type,
|
function.type,
|
||||||
function,
|
function,
|
||||||
irModule.descriptor.privateFunctionSymbolName(index)
|
irModule.descriptor.privateFunctionSymbolName(index, it.second.name)
|
||||||
)!!
|
)!!
|
||||||
}
|
}
|
||||||
context.privateFunctions = privateFunctions
|
context.privateFunctions = privateFunctions
|
||||||
@@ -107,12 +107,12 @@ internal fun emitLLVM(context: Context) {
|
|||||||
val privateClasses = moduleDFG!!.symbolTable.getPrivateClassesTableForExport()
|
val privateClasses = moduleDFG!!.symbolTable.getPrivateClassesTableForExport()
|
||||||
|
|
||||||
privateClasses.forEachIndexed { index, it ->
|
privateClasses.forEachIndexed { index, it ->
|
||||||
val typeInfoPtr = codegenVisitor.codegen.typeInfoValue(it)
|
val typeInfoPtr = codegenVisitor.codegen.typeInfoValue(it.first)
|
||||||
LLVMAddAlias(
|
LLVMAddAlias(
|
||||||
context.llvmModule,
|
context.llvmModule,
|
||||||
typeInfoPtr.type,
|
typeInfoPtr.type,
|
||||||
typeInfoPtr,
|
typeInfoPtr,
|
||||||
irModule.descriptor.privateClassSymbolName(index)
|
irModule.descriptor.privateClassSymbolName(index, it.second.name)
|
||||||
)!!
|
)!!
|
||||||
}
|
}
|
||||||
context.privateClasses = privateClasses
|
context.privateClasses = privateClasses
|
||||||
@@ -2019,10 +2019,10 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
|
|||||||
val dfgSymbol = callee.dfgSymbol
|
val dfgSymbol = callee.dfgSymbol
|
||||||
val functionIndex = callee.functionIndex
|
val functionIndex = callee.functionIndex
|
||||||
val function = if (callee.moduleDescriptor == context.irModule!!.descriptor) {
|
val function = if (callee.moduleDescriptor == context.irModule!!.descriptor) {
|
||||||
codegen.llvmFunction(context.privateFunctions[functionIndex])
|
codegen.llvmFunction(context.privateFunctions[functionIndex].first)
|
||||||
} else {
|
} else {
|
||||||
context.llvm.externalFunction(
|
context.llvm.externalFunction(
|
||||||
callee.moduleDescriptor.privateFunctionSymbolName(functionIndex),
|
callee.moduleDescriptor.privateFunctionSymbolName(functionIndex, callee.dfgSymbol.name),
|
||||||
codegen.getLlvmFunctionType(dfgSymbol),
|
codegen.getLlvmFunctionType(dfgSymbol),
|
||||||
callee.moduleDescriptor.llvmSymbolOrigin
|
callee.moduleDescriptor.llvmSymbolOrigin
|
||||||
|
|
||||||
@@ -2036,10 +2036,10 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
|
|||||||
private fun evaluatePrivateClassReference(classReference: IrPrivateClassReference): LLVMValueRef {
|
private fun evaluatePrivateClassReference(classReference: IrPrivateClassReference): LLVMValueRef {
|
||||||
val classIndex = classReference.classIndex
|
val classIndex = classReference.classIndex
|
||||||
val typeInfoPtr = if (classReference.moduleDescriptor == context.irModule!!.descriptor) {
|
val typeInfoPtr = if (classReference.moduleDescriptor == context.irModule!!.descriptor) {
|
||||||
codegen.typeInfoValue(context.privateClasses[classIndex])
|
codegen.typeInfoValue(context.privateClasses[classIndex].first)
|
||||||
} else {
|
} else {
|
||||||
codegen.importGlobal(
|
codegen.importGlobal(
|
||||||
classReference.moduleDescriptor.privateClassSymbolName(classIndex),
|
classReference.moduleDescriptor.privateClassSymbolName(classIndex, classReference.dfgSymbol.name),
|
||||||
codegen.kTypeInfo,
|
codegen.kTypeInfo,
|
||||||
classReference.moduleDescriptor.llvmSymbolOrigin
|
classReference.moduleDescriptor.llvmSymbolOrigin
|
||||||
)
|
)
|
||||||
|
|||||||
+2
-2
@@ -637,7 +637,7 @@ internal object DataFlowIR {
|
|||||||
assert((entry.value as DataFlowIR.FunctionSymbol.Declared).symbolTableIndex == index) { "Inconsistent function table" }
|
assert((entry.value as DataFlowIR.FunctionSymbol.Declared).symbolTableIndex == index) { "Inconsistent function table" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.map { it.key as FunctionDescriptor }
|
.map { (it.key as FunctionDescriptor) to (it.value as DataFlowIR.FunctionSymbol.Declared) }
|
||||||
.toList()
|
.toList()
|
||||||
|
|
||||||
fun getPrivateClassesTableForExport() =
|
fun getPrivateClassesTableForExport() =
|
||||||
@@ -650,7 +650,7 @@ internal object DataFlowIR {
|
|||||||
assert((entry.value as DataFlowIR.Type.Declared).symbolTableIndex == index) { "Inconsistent class table" }
|
assert((entry.value as DataFlowIR.Type.Declared).symbolTableIndex == index) { "Inconsistent class table" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.map { it.key }
|
.map { it.key to (it.value as DataFlowIR.Type.Declared) }
|
||||||
.toList()
|
.toList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-1
@@ -1191,7 +1191,8 @@ internal object Devirtualization {
|
|||||||
classType = receiver.type,
|
classType = receiver.type,
|
||||||
moduleDescriptor = actualReceiverType.module!!.descriptor,
|
moduleDescriptor = actualReceiverType.module!!.descriptor,
|
||||||
totalClasses = actualReceiverType.module.numberOfClasses,
|
totalClasses = actualReceiverType.module.numberOfClasses,
|
||||||
classIndex = actualReceiverType.symbolTableIndex)
|
classIndex = actualReceiverType.symbolTableIndex,
|
||||||
|
dfgSymbol = actualReceiverType)
|
||||||
val condition =
|
val condition =
|
||||||
if (optimize && index == possibleCallees.size - 1)
|
if (optimize && index == possibleCallees.size - 1)
|
||||||
irTrue() // Don't check last type in optimize mode.
|
irTrue() // Don't check last type in optimize mode.
|
||||||
|
|||||||
Reference in New Issue
Block a user