DFG: Added Type.correspondingValueType
This commit is contained in:
+12
-7
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.backend.konan.optimizations
|
package org.jetbrains.kotlin.backend.konan.optimizations
|
||||||
|
|
||||||
import org.jetbrains.kotlin.backend.konan.Context
|
import org.jetbrains.kotlin.backend.konan.Context
|
||||||
|
import org.jetbrains.kotlin.backend.konan.ValueType
|
||||||
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||||
import sun.misc.Unsafe
|
import sun.misc.Unsafe
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
@@ -223,15 +224,16 @@ internal object DFGSerializer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DeclaredType(val isFinal: Boolean, val isAbstract: Boolean, val index: Int, val superTypes: IntArray,
|
class DeclaredType(val isFinal: Boolean, val isAbstract: Boolean, val correspondingValueType: ValueType?,
|
||||||
val vtable: IntArray, val itable: Array<ItableSlot>) {
|
val index: Int, val superTypes: IntArray, val vtable: IntArray, val itable: Array<ItableSlot>) {
|
||||||
|
|
||||||
constructor(data: ArraySlice) : this(data.readBoolean(), data.readBoolean(), data.readInt(), data.readIntArray(),
|
constructor(data: ArraySlice) : this(data.readBoolean(), data.readBoolean(), data.readNullableInt()?.let { ValueType.values()[it] },
|
||||||
data.readIntArray(), data.readArray { ItableSlot(this) })
|
data.readInt(), data.readIntArray(), data.readIntArray(), data.readArray { ItableSlot(this) })
|
||||||
|
|
||||||
fun write(result: ArraySlice) {
|
fun write(result: ArraySlice) {
|
||||||
result.writeBoolean(isFinal)
|
result.writeBoolean(isFinal)
|
||||||
result.writeBoolean(isAbstract)
|
result.writeBoolean(isAbstract)
|
||||||
|
result.writeNullableInt(correspondingValueType?.ordinal)
|
||||||
result.writeInt(index)
|
result.writeInt(index)
|
||||||
result.writeIntArray(superTypes)
|
result.writeIntArray(superTypes)
|
||||||
result.writeIntArray(vtable)
|
result.writeIntArray(vtable)
|
||||||
@@ -759,10 +761,12 @@ internal object DFGSerializer {
|
|||||||
val types = typeMap.entries
|
val types = typeMap.entries
|
||||||
.sortedBy { it.value }
|
.sortedBy { it.value }
|
||||||
.map {
|
.map {
|
||||||
|
|
||||||
fun buildTypeIntestines(type: DataFlowIR.Type.Declared) =
|
fun buildTypeIntestines(type: DataFlowIR.Type.Declared) =
|
||||||
DeclaredType(
|
DeclaredType(
|
||||||
type.isFinal,
|
type.isFinal,
|
||||||
type.isAbstract,
|
type.isAbstract,
|
||||||
|
type.correspondingValueType,
|
||||||
type.symbolTableIndex,
|
type.symbolTableIndex,
|
||||||
type.superTypes.map { typeMap[it]!! }.toIntArray(),
|
type.superTypes.map { typeMap[it]!! }.toIntArray(),
|
||||||
type.vtable.map { functionSymbolMap[it]!! }.toIntArray(),
|
type.vtable.map { functionSymbolMap[it]!! }.toIntArray(),
|
||||||
@@ -927,8 +931,8 @@ internal object DFGSerializer {
|
|||||||
val symbolTableIndex = public.intestines.index
|
val symbolTableIndex = public.intestines.index
|
||||||
if (symbolTableIndex >= 0)
|
if (symbolTableIndex >= 0)
|
||||||
++module.numberOfClasses
|
++module.numberOfClasses
|
||||||
DataFlowIR.Type.Public(public.hash, public.intestines.isFinal,
|
DataFlowIR.Type.Public(public.hash, public.intestines.isFinal, public.intestines.isAbstract,
|
||||||
public.intestines.isAbstract, module, symbolTableIndex, public.name).also {
|
public.intestines.correspondingValueType, module, symbolTableIndex, public.name).also {
|
||||||
publicTypesMap.put(it.hash, it)
|
publicTypesMap.put(it.hash, it)
|
||||||
allTypes += it
|
allTypes += it
|
||||||
}
|
}
|
||||||
@@ -939,7 +943,8 @@ internal object DFGSerializer {
|
|||||||
if (symbolTableIndex >= 0)
|
if (symbolTableIndex >= 0)
|
||||||
++module.numberOfClasses
|
++module.numberOfClasses
|
||||||
DataFlowIR.Type.Private(privateTypeIndex++, private.intestines.isFinal,
|
DataFlowIR.Type.Private(privateTypeIndex++, private.intestines.isFinal,
|
||||||
private.intestines.isAbstract, module, symbolTableIndex, private.name).also {
|
private.intestines.isAbstract, private.intestines.correspondingValueType,
|
||||||
|
module, symbolTableIndex, private.name).also {
|
||||||
allTypes += it
|
allTypes += it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-15
@@ -16,13 +16,10 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.backend.konan.optimizations
|
package org.jetbrains.kotlin.backend.konan.optimizations
|
||||||
|
|
||||||
import org.jetbrains.kotlin.backend.common.descriptors.allParameters
|
import org.jetbrains.kotlin.backend.konan.*
|
||||||
import org.jetbrains.kotlin.backend.konan.Context
|
|
||||||
import org.jetbrains.kotlin.backend.konan.descriptors.isAbstract
|
import org.jetbrains.kotlin.backend.konan.descriptors.isAbstract
|
||||||
import org.jetbrains.kotlin.backend.konan.descriptors.isInterface
|
import org.jetbrains.kotlin.backend.konan.descriptors.isInterface
|
||||||
import org.jetbrains.kotlin.backend.konan.irasdescriptors.*
|
import org.jetbrains.kotlin.backend.konan.irasdescriptors.*
|
||||||
import org.jetbrains.kotlin.backend.konan.isObjCClass
|
|
||||||
import org.jetbrains.kotlin.backend.konan.isValueType
|
|
||||||
import org.jetbrains.kotlin.backend.konan.llvm.functionName
|
import org.jetbrains.kotlin.backend.konan.llvm.functionName
|
||||||
import org.jetbrains.kotlin.backend.konan.llvm.isExported
|
import org.jetbrains.kotlin.backend.konan.llvm.isExported
|
||||||
import org.jetbrains.kotlin.backend.konan.llvm.localHash
|
import org.jetbrains.kotlin.backend.konan.llvm.localHash
|
||||||
@@ -43,8 +40,6 @@ import org.jetbrains.kotlin.name.FqName
|
|||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue
|
import org.jetbrains.kotlin.resolve.constants.ConstantValue
|
||||||
import org.jetbrains.kotlin.resolve.constants.IntValue
|
import org.jetbrains.kotlin.resolve.constants.IntValue
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.typeUtil.immediateSupertypes
|
import org.jetbrains.kotlin.types.typeUtil.immediateSupertypes
|
||||||
|
|
||||||
@@ -52,7 +47,7 @@ internal object DataFlowIR {
|
|||||||
|
|
||||||
abstract class Type {
|
abstract class Type {
|
||||||
// Special marker type forbidding devirtualization on its instances.
|
// Special marker type forbidding devirtualization on its instances.
|
||||||
object Virtual : Declared(false, true, null, -1)
|
object Virtual : Declared(false, true, null, null, -1)
|
||||||
|
|
||||||
class External(val hash: Long, val name: String? = null) : Type() {
|
class External(val hash: Long, val name: String? = null) : Type() {
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
@@ -71,14 +66,16 @@ internal object DataFlowIR {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class Declared(val isFinal: Boolean, val isAbstract: Boolean, val module: Module?, val symbolTableIndex: Int) : Type() {
|
abstract class Declared(val isFinal: Boolean, val isAbstract: Boolean, val correspondingValueType: ValueType?,
|
||||||
|
val module: Module?, val symbolTableIndex: Int) : Type() {
|
||||||
val superTypes = mutableListOf<Type>()
|
val superTypes = mutableListOf<Type>()
|
||||||
val vtable = mutableListOf<FunctionSymbol>()
|
val vtable = mutableListOf<FunctionSymbol>()
|
||||||
val itable = mutableMapOf<Long, FunctionSymbol>()
|
val itable = mutableMapOf<Long, FunctionSymbol>()
|
||||||
}
|
}
|
||||||
|
|
||||||
class Public(val hash: Long, isFinal: Boolean, isAbstract: Boolean, module: Module, symbolTableIndex: Int, val name: String? = null)
|
class Public(val hash: Long, isFinal: Boolean, isAbstract: Boolean, correspondingValueType: ValueType?,
|
||||||
: Declared(isFinal, isAbstract, module, symbolTableIndex) {
|
module: Module, symbolTableIndex: Int, val name: String? = null)
|
||||||
|
: Declared(isFinal, isAbstract, correspondingValueType, module, symbolTableIndex) {
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (this === other) return true
|
if (this === other) return true
|
||||||
if (other !is Public) return false
|
if (other !is Public) return false
|
||||||
@@ -95,8 +92,9 @@ internal object DataFlowIR {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Private(val index: Int, isFinal: Boolean, isAbstract: Boolean, module: Module, symbolTableIndex: Int, val name: String? = null)
|
class Private(val index: Int, isFinal: Boolean, isAbstract: Boolean, correspondingValueType: ValueType?,
|
||||||
: Declared(isFinal, isAbstract, module, symbolTableIndex) {
|
module: Module, symbolTableIndex: Int, val name: String? = null)
|
||||||
|
: Declared(isFinal, isAbstract, correspondingValueType, module, symbolTableIndex) {
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (this === other) return true
|
if (this === other) return true
|
||||||
if (other !is Private) return false
|
if (other !is Private) return false
|
||||||
@@ -481,12 +479,13 @@ internal object DataFlowIR {
|
|||||||
|
|
||||||
val isFinal = descriptor.isFinal()
|
val isFinal = descriptor.isFinal()
|
||||||
val isAbstract = descriptor.isAbstract()
|
val isAbstract = descriptor.isAbstract()
|
||||||
val placeToClassTable = !descriptor.defaultType.isValueType()
|
val correspondingValueType = descriptor.defaultType.correspondingValueType
|
||||||
|
val placeToClassTable = correspondingValueType == null
|
||||||
val symbolTableIndex = if (placeToClassTable) module.numberOfClasses++ else -1
|
val symbolTableIndex = if (placeToClassTable) module.numberOfClasses++ else -1
|
||||||
val type = if (descriptor.isExported())
|
val type = if (descriptor.isExported())
|
||||||
Type.Public(name.localHash.value, isFinal, isAbstract, module, symbolTableIndex, takeName { name })
|
Type.Public(name.localHash.value, isFinal, isAbstract, correspondingValueType, module, symbolTableIndex, takeName { name })
|
||||||
else
|
else
|
||||||
Type.Private(privateTypeIndex++, isFinal, isAbstract, module, symbolTableIndex, takeName { name })
|
Type.Private(privateTypeIndex++, isFinal, isAbstract, correspondingValueType, module, symbolTableIndex, takeName { name })
|
||||||
if (!isAbstract) {
|
if (!isAbstract) {
|
||||||
val vtableBuilder = context.getVtableBuilder(descriptor)
|
val vtableBuilder = context.getVtableBuilder(descriptor)
|
||||||
type.vtable += vtableBuilder.vtableEntries.map { mapFunction(it.getImplementation(context)!!) }
|
type.vtable += vtableBuilder.vtableEntries.map { mapFunction(it.getImplementation(context)!!) }
|
||||||
|
|||||||
Reference in New Issue
Block a user