Optimize vtable building [KT-40652]

This commit is contained in:
Elena Lepilkina
2020-08-07 11:36:31 +03:00
committed by LepilkinaElena
parent 4f725387ff
commit b57b81afa8
@@ -286,6 +286,7 @@ internal class ClassLayoutBuilder(val irClass: IrClass, val context: Context, va
val methods = irClass.sortedOverridableOrOverridingMethods val methods = irClass.sortedOverridableOrOverridingMethods
val newVtableSlots = mutableListOf<OverriddenFunctionInfo>() val newVtableSlots = mutableListOf<OverriddenFunctionInfo>()
val overridenVtableSlots = mutableMapOf<IrSimpleFunction, OverriddenFunctionInfo>()
DEBUG_OUTPUT(0) { DEBUG_OUTPUT(0) {
println() println()
@@ -300,21 +301,30 @@ internal class ClassLayoutBuilder(val irClass: IrClass, val context: Context, va
println("BUILDING INHERITED vTable") println("BUILDING INHERITED vTable")
} }
val inheritedVtableSlots = superVtableEntries.map { superMethod -> val superVtableMap = superVtableEntries.groupBy { it.function }
val overridingMethod = methods.singleOrNull { it.overrides(superMethod.function) } methods.forEach { overridingMethod ->
if (overridingMethod == null) { overridingMethod.allOverriddenFunctions.forEach {
val superMethods = superVtableMap[it]
DEBUG_OUTPUT(0) { println("Taking super ${superMethod.overriddenFunction.render()} -> ${superMethod.function.render()}") } if (superMethods?.isNotEmpty() == true) {
newVtableSlots.add(OverriddenFunctionInfo(overridingMethod, it))
superMethod superMethods.forEach { superMethod ->
} else { overridenVtableSlots[superMethod.overriddenFunction] =
newVtableSlots.add(OverriddenFunctionInfo(overridingMethod, superMethod.function))
DEBUG_OUTPUT(0) { println("Taking overridden ${superMethod.overriddenFunction.render()} -> ${overridingMethod.render()}") }
OverriddenFunctionInfo(overridingMethod, superMethod.overriddenFunction) OverriddenFunctionInfo(overridingMethod, superMethod.overriddenFunction)
} }
} }
}
}
val inheritedVtableSlots = superVtableEntries.map { superMethod ->
overridenVtableSlots[superMethod.overriddenFunction]?.also {
DEBUG_OUTPUT(0) {
println("Taking overridden ${superMethod.overriddenFunction.render()} -> ${it.function.render()}")
}
} ?: superMethod.also {
DEBUG_OUTPUT(0) {
println("Taking super ${superMethod.overriddenFunction.render()} -> ${superMethod.function.render()}")
}
}
}
// Add all possible (descriptor, overriddenDescriptor) edges for now, redundant will be removed later. // Add all possible (descriptor, overriddenDescriptor) edges for now, redundant will be removed later.
methods.mapTo(newVtableSlots) { OverriddenFunctionInfo(it, it) } methods.mapTo(newVtableSlots) { OverriddenFunctionInfo(it, it) }